#include #include #include #include using namespace std; using namespace __gnu_cxx; // for SGI extensions compose1 and select1st using namespace boost; // define dummy visitor class class dummy : public boost::static_visitor<> { public: template void operator()(const T &x) const { cout << x << endl; } }; typedef variant TMixed; typedef pair TPair; int main() { TPair p=make_pair(0, "zero"); vector v; v.push_back( make_pair(1, "int") ); v.push_back( make_pair(3.4, "double") ); dummy _dummy; for_each( v.begin(), v.end(), compose1(apply_visitor(_dummy), select1st() ) ); // yields a const error // the const error comes from here compose1(apply_visitor(_dummy), select1st() )(p); // but this works apply_visitor(_dummy)( select1st()(p) ); // again in detail const select1st g=select1st(); const apply_visitor_delayed_t f(_dummy); // remove the const and f( g(p) ); // this line works! }