/////////////////////////////////////////////////////////////////////////////// // new_switch.cpp // // Copyright 2011 Eric Niebler // Copyright Pierre Esterie & Joel Falcou. // Distributed under 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 #include #include namespace proto = boost::proto; struct MyCases { template struct case_ : proto::not_ {}; }; template<> struct MyCases::case_ : proto::_ {}; template<> struct MyCases::case_ : proto::_ {}; struct ArityOf; struct ArityOfCases { template struct case_ : proto::not_ {}; }; template<> struct ArityOfCases::case_ > : boost::proto::when {}; template<> struct ArityOfCases::case_ > : boost::proto::when {}; struct ArityOf : boost::proto::switch_< ArityOfCases , proto::arity_of() > {}; void test_switch() { // Tests for backward compatibility proto::assert_matches >(proto::lit(1) >> 'a'); proto::assert_matches >(proto::lit(1) + 'a'); proto::assert_matches_not >(proto::lit(1) << 'a'); //Test new matching on the Transform result type ArityOf ar; proto::assert_matches_not(proto::lit(1)); proto::assert_matches(proto::lit(1) + 2); proto::assert_matches(!proto::lit(1)); BOOST_CHECK_EQUAL(ar(!proto::lit(1)), false); BOOST_CHECK_EQUAL(ar(proto::lit(1) + 2), true); } using namespace boost::unit_test; /////////////////////////////////////////////////////////////////////////////// // init_unit_test_suite // test_suite* init_unit_test_suite(int argc, char* argv[]) { test_suite *test = BOOST_TEST_SUITE("test proto::switch_<>"); test->add(BOOST_TEST_CASE(&test_switch)); return test; }