| 1 | /*============================================================================= |
| 2 | Copyright (c) 2001-2007 Joel de Guzman |
| 3 | |
| 4 | Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 5 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 6 | ==============================================================================*/ |
| 7 | #include <iostream> |
| 8 | #include <string> |
| 9 | |
| 10 | #include <boost/phoenix/core/argument.hpp> |
| 11 | #include <boost/phoenix/core/reference.hpp> |
| 12 | #include <boost/phoenix/core/value.hpp> |
| 13 | #include <boost/detail/lightweight_test.hpp> |
| 14 | |
| 15 | using boost::phoenix::cref; |
| 16 | using boost::phoenix::ref; |
| 17 | using boost::phoenix::val; |
| 18 | |
| 19 | |
| 20 | int |
| 21 | main() |
| 22 | { |
| 23 | #ifndef BOOST_PHOENIX_NO_PREDEFINED_TERMINALS |
| 24 | using boost::phoenix::arg_names::_1; |
| 25 | using boost::phoenix::arg_names::arg1; |
| 26 | using boost::phoenix::arg_names::arg2; |
| 27 | #else |
| 28 | boost::phoenix::arg_names::_1_type _1; |
| 29 | boost::phoenix::arg_names::arg1_type arg1; |
| 30 | boost::phoenix::arg_names::arg2_type arg2; |
| 31 | #endif |
| 32 | char c1 = '1'; |
| 33 | int i1 = 1, i2 = 2, i = 4; |
| 34 | const char* s2 = "2" ; |
| 35 | |
| 36 | |
| 37 | |
| 38 | /////////////////////////////////////////////////////////////////////////// |
| 39 | // |
| 40 | // Values, references and arguments |
| 41 | // |
| 42 | /////////////////////////////////////////////////////////////////////////// |
| 43 | |
| 44 | // argument |
| 45 | BOOST_TEST(arg1(c1) == c1); |
| 46 | BOOST_TEST(arg1(i1, i2) == i1); |
| 47 | BOOST_TEST(arg2(i1, s2) == s2); |
| 48 | BOOST_TEST(&(arg1(c1)) == &c1); // must be an lvalue |
| 49 | |
| 50 | // value |
| 51 | val(t: ' ')(); |
| 52 | val(t: " " )(); |
| 53 | std::cout << val(t: "Hello," )() << val(t: ' ')() << val(t: "World" )() << std::endl; |
| 54 | BOOST_TEST(val(3)() == 3); |
| 55 | BOOST_TEST(val("Hello, world" )() == std::string("Hello, world" )); |
| 56 | BOOST_TEST(val(_1)(i1) == i1); |
| 57 | |
| 58 | // should not compile: |
| 59 | #ifdef PHOENIX_SHOULD_NOT_COMPILE_TEST |
| 60 | &val(_1)(i1); // should return an rvalue |
| 61 | #endif |
| 62 | |
| 63 | // reference |
| 64 | BOOST_TEST(cref(i)() == ref(i)()); |
| 65 | BOOST_TEST(cref(i)() == 4); |
| 66 | BOOST_TEST(i == 4); |
| 67 | BOOST_TEST(ref(++i)() == 5); |
| 68 | BOOST_TEST(i == 5); |
| 69 | |
| 70 | // should not compile: |
| 71 | #ifdef PHOENIX_SHOULD_NOT_COMPILE_TEST |
| 72 | ref(arg1); |
| 73 | #endif |
| 74 | |
| 75 | // testing consts |
| 76 | int const ic = 123; |
| 77 | BOOST_TEST(arg1(ic) == 123); |
| 78 | |
| 79 | // should not compile: |
| 80 | #ifdef PHOENIX_SHOULD_NOT_COMPILE_TEST |
| 81 | arg1(); |
| 82 | #endif |
| 83 | |
| 84 | return boost::report_errors(); |
| 85 | } |
| 86 | |