// ----------------------------------------------------------------------
//
// zmtIFtest1.cc -- Validate IteratorFilter on native array type
//
// History:
//   18-Feb-2000  WEB  Initial draft
//   22-Feb-2000  WEB  Rearrange for closer conformance to library
//     container version
//   24-Feb-2000  WEB  Improve Zoom compatibility
//
// ----------------------------------------------------------------------


#include "ZMutility/ZMenvironment.h"

#include <iostream>

#include "ZMtools/IteratorFilter.h"


// ----------------------------------------
// Specify container information:
// ----------------------------------------

int const  NA( 20 );        // Desired container size
typedef    int  A[NA];      // Desired container type
typedef    int const *  It; // Desired iterator type


// ----------------------------------------
// Specify filter function information:
// ----------------------------------------

typedef  bool (*FilterFctn) ( int ); // Desired filter function type
bool odd   ( int i )  { return i % 2;          } // 1st filter function
bool triple( int i )  { return i == i / 3 * 3; } // 2nd filter function


// ----------------------------------------
// Specify IteratorFilter (IF) information:
// ----------------------------------------

ZM_USING_NAMESPACE( zmt )
typedef IteratorFilter<It,FilterFctn>  Phil; // Desired IF type


// ----------------------------------------
// Start testing:
// ----------------------------------------

int  main( int argc, char const * argv[] )  {

  std::cout << argv[0] << std::endl;

  A   a;           // Container
  It  end( a+NA ); // Container's end

  // Initialize container:
  for ( int k( 0 );  k != NA;  ++k )
    a[k] = k;

  // Prepare IteratorFilter objects:
  int const  NP = 2;
  Phil  p[NP] = { Phil(end, &odd) };
  p[1] = Phil(end, &triple);

  // Filter the container with each IteratorFilter:
  for ( int k( 0 );  k != NP;  ++k )  {
    for ( It it( a );  p[k](it);  ++it )
      std::cout << *it << ' ';
    std::cout << std::endl;
  }

  // Go home:
  return 0;

}  // main()
