| 1 | /*============================================================================= |
|---|
| 2 | Copyright (C) 1999-2003 Jaakko Järvi |
|---|
| 3 | Copyright (c) 2003 Joel de Guzman |
|---|
| 4 | |
|---|
| 5 | Use, modification and distribution is subject to the Boost Software |
|---|
| 6 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 7 | http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 8 | ==============================================================================*/ |
|---|
| 9 | #include <boost/detail/lightweight_test.hpp> |
|---|
| 10 | #include <boost/spirit/fusion/sequence/tuple.hpp> |
|---|
| 11 | #include <boost/spirit/fusion/sequence/get.hpp> |
|---|
| 12 | #include <boost/spirit/fusion/sequence/tie.hpp> |
|---|
| 13 | #include <boost/spirit/fusion/sequence/make_tuple.hpp> |
|---|
| 14 | |
|---|
| 15 | namespace |
|---|
| 16 | { |
|---|
| 17 | // something to prevent warnings for unused variables |
|---|
| 18 | template<class T> void dummy(const T&) {} |
|---|
| 19 | |
|---|
| 20 | // no public default constructor |
|---|
| 21 | class foo |
|---|
| 22 | { |
|---|
| 23 | public: |
|---|
| 24 | |
|---|
| 25 | explicit foo(int v) : val(v) {} |
|---|
| 26 | |
|---|
| 27 | bool operator==(const foo& other) const |
|---|
| 28 | { |
|---|
| 29 | return val == other.val; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | private: |
|---|
| 33 | |
|---|
| 34 | foo() {} |
|---|
| 35 | int val; |
|---|
| 36 | }; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | int |
|---|
| 40 | main() |
|---|
| 41 | { |
|---|
| 42 | using namespace boost::fusion; |
|---|
| 43 | |
|---|
| 44 | int a; |
|---|
| 45 | char b; |
|---|
| 46 | foo c(5); |
|---|
| 47 | |
|---|
| 48 | tie(a, b, c) = make_tuple(2, 'a', foo(3)); |
|---|
| 49 | BOOST_TEST(a == 2); |
|---|
| 50 | BOOST_TEST(b == 'a'); |
|---|
| 51 | BOOST_TEST(c == foo(3)); |
|---|
| 52 | |
|---|
| 53 | tie(a, ignore, c) = make_tuple((short int)5, false, foo(5)); |
|---|
| 54 | BOOST_TEST(a == 5); |
|---|
| 55 | BOOST_TEST(b == 'a'); |
|---|
| 56 | BOOST_TEST(c == foo(5)); |
|---|
| 57 | |
|---|
| 58 | // testing assignment from std::pair |
|---|
| 59 | int i, j; |
|---|
| 60 | tie (i, j) = std::make_pair(1, 2); |
|---|
| 61 | BOOST_TEST(i == 1 && j == 2); |
|---|
| 62 | |
|---|
| 63 | tuple<int, int, float> ta; |
|---|
| 64 | |
|---|
| 65 | #ifdef E11 |
|---|
| 66 | ta = std::make_pair(1, 2); // should fail, tuple is of length 3, not 2 |
|---|
| 67 | #endif |
|---|
| 68 | |
|---|
| 69 | dummy(ta); |
|---|
| 70 | |
|---|
| 71 | // ties cannot be rebound |
|---|
| 72 | int d = 3; |
|---|
| 73 | tuple<int&> ti(a); |
|---|
| 74 | BOOST_TEST(&get<0>(ti) == &a); |
|---|
| 75 | ti = tuple<int&>(d); |
|---|
| 76 | BOOST_TEST(&get<0>(ti) == &a); |
|---|
| 77 | |
|---|
| 78 | return boost::report_errors(); |
|---|
| 79 | } |
|---|