1 /*============================================================================= 2 Copyright (c) 2001-2007 Joel de Guzman 3 Copyright (c) 2015 John Fletcher 4 5 Distributed under the Boost Software License, Version 1.0. (See accompanying 6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 ==============================================================================*/ 8 #include <boost/core/lightweight_test.hpp> 9 10 #include <boost/phoenix/core.hpp> 11 #include <boost/phoenix/operator.hpp> 12 13 #include <boost/bind.hpp> 14 15 namespace phoenix = boost::phoenix; 16 17 int main()18main() 19 { 20 using phoenix::ref; 21 using phoenix::val; 22 23 { 24 int x = 123; 25 26 BOOST_TEST((ref(x) += 456)() == (123 + 456)); 27 BOOST_TEST(x == 123 + 456); 28 BOOST_TEST((ref(x) -= 456)() == 123); 29 BOOST_TEST(x == 123); 30 BOOST_TEST((ref(x) *= 456)() == 123 * 456); 31 BOOST_TEST(x == 123 * 456); 32 BOOST_TEST((ref(x) /= 456)() == 123); 33 BOOST_TEST(x == 123); 34 35 int& r1 = (ref(x) += 456)(); // should be an lvalue 36 int& r2 = (ref(x) -= 456)(); // should be an lvalue 37 int& r3 = (ref(x) *= 456)(); // should be an lvalue 38 int& r4 = (ref(x) /= 456)(); // should be an lvalue 39 BOOST_TEST(r1 == 123 && r2 == 123 && r3 == 123 && r4 == 123); 40 41 BOOST_TEST((ref(x) %= 456)() == 123 % 456); 42 BOOST_TEST(x == 123 % 456); 43 } 44 45 { 46 BOOST_TEST((-val(123))() == -123); 47 BOOST_TEST((val(123) + 456)() == 123 + 456); 48 BOOST_TEST((val(123) - 456)() == 123 - 456); 49 BOOST_TEST((val(123) * 456)() == 123 * 456); 50 BOOST_TEST((val(123) / 456)() == 123 / 456); 51 BOOST_TEST((val(123) % 456)() == 123 % 456); 52 53 BOOST_TEST((123 + val(456))() == 123 + 456); 54 BOOST_TEST((123 - val(456))() == 123 - 456); 55 BOOST_TEST((123 * val(456))() == 123 * 456); 56 BOOST_TEST((123 / val(456))() == 123 / 456); 57 BOOST_TEST((123 % val(456))() == 123 % 456); 58 } 59 { 60 // Testcase contributed from Philipp Reh, failed in Phoenix V2 61 using boost::phoenix::arg_names::arg1; 62 using boost::phoenix::arg_names::arg2; 63 64 int x[2]; 65 66 BOOST_TEST((&arg1 - &arg2)(x[0], x[1]) == &x[0] - &x[1]); 67 BOOST_TEST((arg1 - arg2)(&x[0], &x[1]) == &x[0] - &x[1]); 68 } 69 70 return boost::report_errors(); 71 } 72