// ----------------------------------------------------------------------
//
// zmtIFtest2.cc -- Validate IteratorFilter on library container type
//
// History:
//   22-Feb-2000  WEB  Initial draft based on rearranged zmtIFtest1.cc
//   24-Feb-2000  WEB  Improve Zoom compatibility
//
// ----------------------------------------------------------------------


#include "ZMutility/ZMenvironment.h"

#include <iostream>
#include <vector>

#include "ZMtools/IteratorFilter.h"


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

int const  NA( 20 );              // Desired container size
typedef    std::vector<int>   A;  // Desired container type
typedef    A::const_iterator  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(NA);          // Container
  It  end( a.end() ); // 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.begin() );  p[k](it);  ++it )
      std::cout << *it << ' ';
    std::cout << std::endl;
  }

  // Go home:
  return 0;

}  // main()
