/*============================================================================= Phoenix V1.2.1 Copyright (c) 2001-2003 Joel de Guzman Use, modification and distribution is subject to the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ #include #include #include #include #include #define PHOENIX_LIMIT 15 #include #include #include #include #include #include using namespace phoenix; using namespace std; /////////////////////////////////////////////////////////////////////////////// struct print_ { // a typical STL style monomorphic functor typedef void result_type; void operator()(int n0) { cout << "got 1 arg " << n0 << " \n"; } }; functor print = print_(); /////////////////////////////////////////////////////////////////////////////// int main() { /////////////////////////////////////////////////////////////////////////////// // // STL algorithms // /////////////////////////////////////////////////////////////////////////////// vector v; v.push_back(1); v.push_back(2); v.push_back(3); v.push_back(4); v.push_back(5); for_each(v.begin(), v.end(), arg1 *= 2); for (int m = 0; m < 5; ++m, (cout << ',')) { cout << v[m]; BOOST_TEST(v[m] == (m+1)*2); } cout << endl; for_each(v.begin(), v.end(), print(arg1)); vector::iterator it = find_if(v.begin(), v.end(), arg1 > 5); if (it != v.end()) cout << *it << endl; /////////////////////////////////////////////////////////////////////////////// // // STL iterators and containers // /////////////////////////////////////////////////////////////////////////////// BOOST_TEST((arg1[0])(v) == v[0]); BOOST_TEST((arg1[1])(v) == v[1]); list l; l.push_back(1); l.push_back(2); l.push_back(3); l.push_back(4); l.push_back(5); list::iterator first = l.begin(); list::iterator last = l.end(); BOOST_TEST((*(++arg1))(first) == 2); BOOST_TEST((*(----arg1))(last) == 4); /////////////////////////////////////////////////////////////////////////////// // // End asserts // /////////////////////////////////////////////////////////////////////////////// return boost::report_errors(); }