/////////////////////////////////////////////////////////////////////////////// // 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) #define BOOST_TEST_MAIN #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() > {}; BOOST_AUTO_TEST_CASE(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); }