1 /*=============================================================================
2 Copyright (c) 1999-2003 Jaakko Jarvi
3 Copyright (c) 2001-2011 Joel de Guzman
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/detail/lightweight_test.hpp>
9 #include <boost/fusion/sequence/intrinsic/at.hpp>
10
11 #if !defined(FUSION_AT)
12 #define FUSION_AT at_c
13 #endif
14
15 #if !defined(FUSION_MAKE)
16 #define FUSION_MAKE BOOST_PP_CAT(make_, FUSION_SEQUENCE)
17 #endif
18
19 #if !defined(FUSION_TIE)
20 #define FUSION_TIE BOOST_PP_CAT(FUSION_SEQUENCE, _tie)
21 #endif
22
23 namespace test_detail
24 {
25 // something to prevent warnings for unused variables
dummy(const T &)26 template<class T> void dummy(const T&) {}
27
28 // no public default constructor
29 class foo
30 {
31 public:
32
foo(int v)33 explicit foo(int v) : val(v) {}
34
operator ==(const foo & other) const35 bool operator==(const foo& other) const
36 {
37 return val == other.val;
38 }
39
40 private:
41
foo()42 foo() {}
43 int val;
44 };
45 }
46
47 void
test()48 test()
49 {
50 using namespace boost::fusion;
51 using namespace test_detail;
52
53 int a;
54 char b;
55 foo c(5);
56
57 FUSION_TIE(a, b, c) = FUSION_MAKE(2, 'a', foo(3));
58 BOOST_TEST(a == 2);
59 BOOST_TEST(b == 'a');
60 BOOST_TEST(c == foo(3));
61
62 FUSION_TIE(a, ignore, c) = FUSION_MAKE((short int)5, false, foo(5));
63 BOOST_TEST(a == 5);
64 BOOST_TEST(b == 'a');
65 BOOST_TEST(c == foo(5));
66
67 int i, j;
68 FUSION_TIE(i, j) = FUSION_MAKE(1, 2);
69 BOOST_TEST(i == 1 && j == 2);
70
71 FUSION_SEQUENCE<int, int, float> ta;
72
73 #if defined(FUSION_TEST_FAIL)
74 ta = std::FUSION_MAKE(1, 2); // should fail, tuple is of length 3, not 2
75 #endif
76
77 dummy(ta);
78
79 // ties cannot be rebound
80 int d = 3;
81 FUSION_SEQUENCE<int&> ti(a);
82 BOOST_TEST(&FUSION_AT<0>(ti) == &a);
83 ti = FUSION_SEQUENCE<int&>(d);
84 BOOST_TEST(&FUSION_AT<0>(ti) == &a);
85 }
86