1 /*=============================================================================
2 Copyright (c) 1999-2003 Jaakko Jarvi
3 Copyright (c) 2001-2011 Joel de Guzman
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 #include <boost/fusion/container/list/cons.hpp>
12 #if !defined(FUSION_AT)
13 #define FUSION_AT at_c
18 // something to prevent warnings for unused variables
19 template<class T> void dummy(const T&) {}
21 // no public default constructor
26 explicit foo(int v) : val(v) {}
28 bool operator==(const foo& other) const
30 return val == other.val;
39 // another class without a public default constructor
40 class no_def_constructor
42 no_def_constructor() {}
46 no_def_constructor(std::string) {}
53 using namespace boost::fusion;
54 using namespace test_detail;
59 FUSION_SEQUENCE<> empty0;
62 #ifndef NO_CONSTRUCT_FROM_NIL
63 FUSION_SEQUENCE<> empty1(empty);
67 FUSION_SEQUENCE<int> t1;
68 BOOST_TEST(FUSION_AT<0>(t1) == int());
70 FUSION_SEQUENCE<float> t2(5.5f);
71 BOOST_TEST(FUSION_AT<0>(t2) > 5.4f && FUSION_AT<0>(t2) < 5.6f);
73 FUSION_SEQUENCE<foo> t3(foo(12));
74 BOOST_TEST(FUSION_AT<0>(t3) == foo(12));
76 FUSION_SEQUENCE<double> t4(t2);
77 BOOST_TEST(FUSION_AT<0>(t4) > 5.4 && FUSION_AT<0>(t4) < 5.6);
79 FUSION_SEQUENCE<int, float> t5;
80 BOOST_TEST(FUSION_AT<0>(t5) == int());
81 BOOST_TEST(FUSION_AT<1>(t5) == float());
83 FUSION_SEQUENCE<int, float> t6(12, 5.5f);
84 BOOST_TEST(FUSION_AT<0>(t6) == 12);
85 BOOST_TEST(FUSION_AT<1>(t6) > 5.4f && FUSION_AT<1>(t6) < 5.6f);
87 FUSION_SEQUENCE<int, float> t7(t6);
88 BOOST_TEST(FUSION_AT<0>(t7) == 12);
89 BOOST_TEST(FUSION_AT<1>(t7) > 5.4f && FUSION_AT<1>(t7) < 5.6f);
91 FUSION_SEQUENCE<long, double> t8(t6);
92 BOOST_TEST(FUSION_AT<0>(t8) == 12);
93 BOOST_TEST(FUSION_AT<1>(t8) > 5.4f && FUSION_AT<1>(t8) < 5.6f);
97 FUSION_SEQUENCE<no_def_constructor, no_def_constructor, no_def_constructor>(
98 std::string("Jaba"), // ok, since the default
99 std::string("Daba"), // constructor is not used
104 dummy(FUSION_SEQUENCE<int, double>());
105 dummy(FUSION_SEQUENCE<int, double>(1,3.14));
107 #if defined(FUSION_TEST_FAIL)
108 dummy(FUSION_SEQUENCE<double&>()); // should fail, no defaults for references
109 dummy(FUSION_SEQUENCE<const double&>()); // likewise
114 dummy(FUSION_SEQUENCE<double&>(dd)); // ok
115 dummy(FUSION_SEQUENCE<const double&>(dd+3.14)); // ok, but dangerous
118 #if defined(FUSION_TEST_FAIL)
119 dummy(FUSION_SEQUENCE<double&>(dd+3.14)); // should fail,
120 // temporary to non-const reference