// ---------------------------------------------------------------------- // // zmtIFtest3.cc -- Validate IteratorFilter on Block<> container type // // History: // 24-Feb-2000 WEB Initial draft based on zmtIFtest2.cc; improve Zoom // compatibility // // ---------------------------------------------------------------------- #include "ZMutility/ZMenvironment.h" #include #include "ZMtools/Block.h" #include "ZMtools/IteratorFilter.h" // ---------------------------------------- // Specify container information: // ---------------------------------------- int const NA( 20 ); // Desired container size ZM_USING_NAMESPACE( zmt ) typedef Block 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 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.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()