#include #include #include #include #include #include #include #include #include #include #include #include #include namespace phoenix = boost::phoenix; namespace fusion = boost::fusion; struct rlc_reorder { struct rlc { }; struct lcr { }; typedef fusion::vector< boost::optional, // 0 - R boost::optional, // 1 - L boost::optional // 2 - C > vector_type; #if WANT_TO_HAVE template struct result { typedef vector_type type; }; template vector_type operator()( const vector_type& v, typename boost::enable_if >::type* id = 0 ) const { return fusion::as_nview<0, 1, 2>( v ); } template vector_type operator()( const vector_type& v, typename boost::enable_if >::type* id = 0 ) const { return fusion::as_nview<2, 0, 1>( v ); } #else template struct result { typedef vector_type type; }; vector_type operator()( const vector_type& v ) const { return fusion::as_nview<2, 0, 1>( v ); } #endif }; const phoenix::function reorder = rlc_reorder(); int main(int argc, char * argv[]) { using boost::optional; using fusion::at_c; using phoenix::arg_names::arg1; using phoenix::arg_names::arg2; typedef fusion::vector< optional, optional, optional > rlc_type; { rlc_type rlc; at_c<0>( rlc ) = 1; // R at_c<1>( rlc ) = 2; // L at_c<2>( rlc ) = 3; // C BOOST_TEST( at_c<0>( rlc ) && at_c<1>( rlc ) && at_c<2>( rlc ) ); BOOST_TEST( *at_c<0>( rlc ) == 1 ); BOOST_TEST( *at_c<1>( rlc ) == 2 ); BOOST_TEST( *at_c<2>( rlc ) == 3 ); } { rlc_type lcr; at_c<0>( lcr ) = 2; // L at_c<1>( lcr ) = 3; // C at_c<2>( lcr ) = 1; // R rlc_type rlc; #if WANT_TO_HAVE rlc = reorder( arg1, arg2 ) (rlc, rlc_reorder::lcr() ); #else rlc = reorder( arg1 )( rlc ); #endif BOOST_TEST( at_c<0>( rlc ) && at_c<1>( rlc ) && at_c<2>( rlc ) ); BOOST_TEST( *at_c<0>( rlc ) == 1 ); BOOST_TEST( *at_c<1>( rlc ) == 2 ); BOOST_TEST( *at_c<2>( rlc ) == 3 ); } return boost::report_errors(); }