/////////////////////////////////////////////////////////////////////////////// // constrained_ops.cpp // // Copyright 2010 Thomas Heller // Copyright 2011 Eric Niebler // // 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 using namespace boost; typedef proto::terminal::type term; struct equation; struct addition: proto::or_ < proto::terminal, proto::plus > {}; struct equation: proto::or_ < proto::equal_to > {}; template struct extension; struct my_domain: proto::domain < proto::pod_generator, equation, proto::default_domain > {}; template struct lhs_extension; struct my_lhs_domain: proto::domain < proto::pod_generator, addition, my_domain > {}; template struct rhs_extension; struct my_rhs_domain: proto::domain < proto::pod_generator, addition, my_domain > {}; template struct extension { BOOST_PROTO_BASIC_EXTENDS( Expr , extension , my_domain ) void test() const {} }; template struct lhs_extension { BOOST_PROTO_BASIC_EXTENDS( Expr , lhs_extension , my_lhs_domain ) }; template struct rhs_extension { BOOST_PROTO_BASIC_EXTENDS( Expr , rhs_extension , my_rhs_domain ) }; void test_constrained_ops() { lhs_extension const i = {}; rhs_extension const j = {}; proto::assert_matches_not(i); // false proto::assert_matches_not(j); // false proto::assert_matches_not(i + i); // false proto::assert_matches_not(j + j); // false #if 0 proto::assert_matches_not(i + j); // compile error (by design) proto::assert_matches_not(j + i); // compile error (by design) #endif proto::assert_matches(i == j); // true proto::assert_matches(i == j + j); // true proto::assert_matches(i + i == j); // true proto::assert_matches(i + i == j + j); // 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 constrained EDSLs"); test->add(BOOST_TEST_CASE(&test_constrained_ops)); return test; }