diff --git a/test/Jamfile b/test/Jamfile index 45bbdd86..d4275f4b 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -92,6 +92,9 @@ project [ run sequence/map_comparison.cpp : : : : ] [ run sequence/map_construction.cpp : : : : ] [ run sequence/map_copy.cpp : : : : ] + [ run sequence/map_misc.cpp : : : : ] + [ run sequence/map_move.cpp : : : : ] + [ run sequence/map_mutate.cpp : : : : ] [ run sequence/map_tie.cpp : : : : ] [ run sequence/nview.cpp : : : : ] [ run sequence/reverse_view.cpp : : : : ] diff --git a/test/sequence/deque_move.cpp b/test/sequence/deque_move.cpp index d096f3b1..c1f126eb 100644 --- a/test/sequence/deque_move.cpp +++ b/test/sequence/deque_move.cpp @@ -13,7 +13,9 @@ #include -#define FUSION_SEQUENCE boost::fusion::deque +#define FUSION_SEQUENCE boost::fusion::deque> +#define FUSION_SEQUENCE2 boost::fusion::deque, x> + #include "move.hpp" #else diff --git a/test/sequence/map_misc.cpp b/test/sequence/map_misc.cpp new file mode 100644 index 00000000..256a16f4 --- /dev/null +++ b/test/sequence/map_misc.cpp @@ -0,0 +1,167 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2013 Joel de Guzman + Copyright (c) 2006 Dan Marsden + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +==============================================================================*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct k1 {}; +struct k2 {}; +struct k3 {}; +struct k4 {}; + +template +struct is_same +{ +}; + +namespace fn = boost::fusion; + +struct test_intrinsics1 +{ + // test at, begin, end, next, prior, advance, size, deref, etc. + + typedef fn::map< + fn::pair, fn::pair, + fn::pair, fn::pair > + sequence; + + typedef boost::mpl::begin::type first; + typedef boost::mpl::next::type second; + typedef boost::mpl::next::type third; + typedef boost::mpl::next::type fourth; + typedef boost::mpl::end::type last; + + BOOST_STATIC_ASSERT((boost::is_same< + boost::mpl::deref::type, fn::pair >::value)); + + BOOST_STATIC_ASSERT((boost::is_same< + boost::mpl::deref::type, fn::pair >::value)); + + BOOST_STATIC_ASSERT((boost::is_same< + boost::mpl::deref::type, fn::pair >::value)); + + BOOST_STATIC_ASSERT((boost::is_same< + boost::mpl::deref::type, fn::pair >::value)); + + BOOST_STATIC_ASSERT((boost::is_same< + boost::mpl::at_c::type, fn::pair >::value)); + + BOOST_STATIC_ASSERT((boost::is_same< + boost::mpl::front::type, fn::pair >::value)); + + BOOST_STATIC_ASSERT((boost::is_same< + boost::mpl::deref< + boost::mpl::advance_c::type>::type, fn::pair >::value)); + + BOOST_STATIC_ASSERT((boost::mpl::size::value == 4)); + BOOST_STATIC_ASSERT(!(boost::mpl::empty::value)); + BOOST_STATIC_ASSERT((boost::mpl::distance::value == 2)); + + typedef boost::mpl::prior::type fourth_; + typedef boost::mpl::prior::type third_; + typedef boost::mpl::prior::type second_; + typedef boost::mpl::prior::type first_; + + BOOST_STATIC_ASSERT((boost::is_same< + boost::mpl::deref::type, fn::pair >::value)); + + BOOST_STATIC_ASSERT((boost::is_same< + boost::mpl::deref::type, fn::pair >::value)); + + BOOST_STATIC_ASSERT((boost::is_same< + boost::mpl::deref::type, fn::pair >::value)); + + BOOST_STATIC_ASSERT((boost::is_same< + boost::mpl::deref::type, fn::pair >::value)); + + BOOST_STATIC_ASSERT((boost::is_same< + boost::mpl::back::type, fn::pair >::value)); + +}; + +void +test() +{ + using namespace boost::fusion; + + { // testing const sequences + + const map, pair > t1(5, 3.3f); + BOOST_TEST(at_c<0>(t1).second == 5); + BOOST_TEST(at_c<1>(t1).second == 3.3f); + } + + { // testing at works with MPL integral constants + const map, pair > t1(101, 'z'); + BOOST_TEST(boost::fusion::at >(t1).second == 101); + BOOST_TEST(boost::fusion::at >(t1).second == 'z'); + // explicitly try something other than mpl::int_ + BOOST_TEST((boost::fusion::at >(t1).second == 101)); + BOOST_TEST((boost::fusion::at >(t1).second == 'z')); + } + + { // testing size & empty + + typedef map, pair, pair > t1; + typedef map<> t2; + + BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 3); + BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 0); + BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty::value); + BOOST_STATIC_ASSERT(boost::fusion::result_of::empty::value); + } + + { // testing front & back + + typedef map, pair, pair > tup; + tup t(1, 2.2f, std::string("Kimpo")); + + BOOST_TEST(front(t).second == 1); + BOOST_TEST(back(t).second == "Kimpo"); + } + + { // testing is_sequence + + typedef map, pair, pair > t1; + typedef map<> t2; + typedef map > t3; + + BOOST_STATIC_ASSERT(traits::is_sequence::value); + BOOST_STATIC_ASSERT(traits::is_sequence::value); + BOOST_STATIC_ASSERT(traits::is_sequence::value); + BOOST_STATIC_ASSERT(!traits::is_sequence::value); + BOOST_STATIC_ASSERT(!traits::is_sequence::value); + } + + { // testing mpl compatibility + + // test an algorithm + typedef map, pair, pair > t1; + typedef boost::mpl::find >::type iter; + typedef boost::mpl::deref::type type; + BOOST_STATIC_ASSERT((boost::is_same >::value)); + } +} + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/test/sequence/map_move.cpp b/test/sequence/map_move.cpp new file mode 100644 index 00000000..77154406 --- /dev/null +++ b/test/sequence/map_move.cpp @@ -0,0 +1,39 @@ +/*============================================================================= + Copyright (c) 2012 Joel de Guzman + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +==============================================================================*/ +#define BOOST_FUSION_DONT_USE_PREPROCESSED_FILES // $$$ JDG temp $$$ + +#include + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +#include + +struct k1 {}; +struct k2 {}; + +#define FUSION_SEQUENCE boost::fusion::map>> + +#define FUSION_SEQUENCE2 boost::fusion::map< \ + boost::fusion::pair>, \ + boost::fusion::pair> + +#include "move.hpp" + +#else +#include +#endif + +int +main() +{ +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + test(); +#endif + + return boost::report_errors(); +} + diff --git a/test/sequence/map_mutate.cpp b/test/sequence/map_mutate.cpp new file mode 100644 index 00000000..afe78ad6 --- /dev/null +++ b/test/sequence/map_mutate.cpp @@ -0,0 +1,69 @@ +/*============================================================================= + Copyright (c) 1999-2003 Jaakko Jarvi + Copyright (c) 2001-2011 Joel de Guzman + Copyright (c) 2006 + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +==============================================================================*/ +#include +#include +#include + +struct k1 {}; +struct k2 {}; +struct k3 {}; +struct k4 {}; + +namespace test_detail +{ + // no public default constructor + class foo + { + public: + + explicit foo(int v) : val(v) {} + + bool operator==(const foo& other) const + { + return val == other.val; + } + + private: + + foo() {} + int val; + }; +} + +void +test() +{ + using namespace boost::fusion; + using namespace test_detail; + + map< + pair, + pair, + pair, + pair + > t1(5, 12.2f, true, foo(4)); + + at_c<0>(t1).second = 6; + at_c<1>(t1).second = 2.2f; + at_c<2>(t1).second = false; + at_c<3>(t1).second = foo(5); + + BOOST_TEST(at_c<0>(t1).second == 6); + BOOST_TEST(at_c<1>(t1).second > 2.1f && at_c<1>(t1).second < 2.3f); + BOOST_TEST(at_c<2>(t1).second == false); + BOOST_TEST(at_c<3>(t1).second == foo(5)); +} + +int +main() +{ + test(); + return boost::report_errors(); +} + diff --git a/test/sequence/move.hpp b/test/sequence/move.hpp index 1ffeceee..febbc2bb 100644 --- a/test/sequence/move.hpp +++ b/test/sequence/move.hpp @@ -73,7 +73,7 @@ namespace test_detail return T(); } - typedef FUSION_SEQUENCE> return_type; + typedef FUSION_SEQUENCE return_type; return_type generate() @@ -84,7 +84,7 @@ namespace test_detail return return_type(); } - typedef FUSION_SEQUENCE, x> return_type2; + typedef FUSION_SEQUENCE2 return_type2; return_type2 generate2() diff --git a/test/sequence/vector_move.cpp b/test/sequence/vector_move.cpp index 23a82851..3f96d72a 100644 --- a/test/sequence/vector_move.cpp +++ b/test/sequence/vector_move.cpp @@ -12,7 +12,9 @@ #include -#define FUSION_SEQUENCE boost::fusion::vector +#define FUSION_SEQUENCE boost::fusion::vector> +#define FUSION_SEQUENCE2 boost::fusion::vector, x> + #include "move.hpp" #else