Added test for the new ADAPT_STRUCT API capable to deduce member types.

This commit is contained in:
Damien Buhl (alias daminetreg)
2014-06-11 01:43:57 +02:00
parent 0000ca263b
commit 4cf96e14f3
6 changed files with 106 additions and 623 deletions

View File

@ -4,8 +4,6 @@
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_PP_VARIADICS 1
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
@ -51,32 +49,59 @@ namespace ns
private:
int x;
int y;
int z;
public:
point_with_private_attributes(int x, int y):x(x),y(y)
point_with_private_attributes(int x, int y, int z):x(x),y(y),z(z)
{}
};
#endif
}
BOOST_FUSION_ADAPT_STRUCT(
ns::point,
(int, x)
(BOOST_FUSION_ADAPT_AUTO, y)
(, z)
)
#if BOOST_PP_VARIADICS
BOOST_FUSION_ADAPT_STRUCT(
ns::point,
x,
y,
z
)
# if !BOOST_WORKAROUND(__GNUC__,<4)
BOOST_FUSION_ADAPT_STRUCT(
ns::point_with_private_attributes,
x,
y,
z
)
# endif
struct s { int m; };
BOOST_FUSION_ADAPT_STRUCT(s, m)
#else // BOOST_PP_VARIADICS
BOOST_FUSION_ADAPT_STRUCT(
ns::point,
(int, x)
(int, y)
(BOOST_FUSION_ADAPT_AUTO, z)
)
# if !BOOST_WORKAROUND(__GNUC__,<4)
BOOST_FUSION_ADAPT_STRUCT(
ns::point_with_private_attributes,
(int, x)
(int, y)
(BOOST_FUSION_ADAPT_AUTO, z)
)
# endif
struct s { int m; };
BOOST_FUSION_ADAPT_STRUCT(s, (BOOST_FUSION_ADAPT_AUTO, m))
#if !BOOST_WORKAROUND(__GNUC__,<4)
BOOST_FUSION_ADAPT_STRUCT(
ns::point_with_private_attributes,
(int, x)
(int, y)
)
#endif
struct s { int m; };
BOOST_FUSION_ADAPT_STRUCT(s, (int, m))
int
main()
{
@ -88,29 +113,31 @@ main()
std::cout << tuple_delimiter(", ");
{
BOOST_MPL_ASSERT_NOT((traits::is_view<ns::point>));
ns::point p = {123, 456};
BOOST_MPL_ASSERT_NOT((traits::is_view<point>));
point p = {123, 456, 789};
std::cout << at_c<0>(p) << std::endl;
std::cout << at_c<1>(p) << std::endl;
std::cout << at_c<2>(p) << std::endl;
std::cout << p << std::endl;
BOOST_TEST(p == make_vector(123, 456, 4));
BOOST_TEST(p == make_vector(123, 456, 789));
at_c<0>(p) = 6;
at_c<1>(p) = 9;
at_c<2>(p) = 12;
BOOST_TEST(p == make_vector(6, 9, 12));
BOOST_STATIC_ASSERT(boost::fusion::result_of::size<ns::point>::value == 3);
BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<ns::point>::value);
BOOST_STATIC_ASSERT(boost::fusion::result_of::size<point>::value == 3);
BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<point>::value);
BOOST_TEST(front(p) == 6);
BOOST_TEST(back(p) == 9);
BOOST_TEST(back(p) == 12);
}
{
fusion::vector<int, float, int> v1(4, 2, 3);
ns::point v2 = {5, 3, 2};
fusion::vector<long, double, int> v3(5, 4, 2);
vector<int, float, int> v1(4, 2, 2);
point v2 = {5, 3, 3};
vector<long, double, int> v3(5, 4, 4);
BOOST_TEST(v1 < v2);
BOOST_TEST(v1 <= v2);
BOOST_TEST(v2 > v1);
@ -122,16 +149,16 @@ main()
}
{
// conversion from ns::point to vector
ns::point p = {5, 3, 4};
fusion::vector<int, long, int> v(p);
// conversion from point to vector
point p = {5, 3, 3};
vector<int, long, int> v(p);
v = p;
}
{
// conversion from ns::point to list
ns::point p = {5, 3, 4};
fusion::list<int, long, int> l(p);
// conversion from point to list
point p = {5, 3, 3};
list<int, long> l(p);
l = p;
}
@ -154,12 +181,13 @@ main()
#if !BOOST_WORKAROUND(__GNUC__,<4)
{
ns::point_with_private_attributes p(123, 456);
ns::point_with_private_attributes p(123, 456, 789);
std::cout << at_c<0>(p) << std::endl;
std::cout << at_c<1>(p) << std::endl;
std::cout << at_c<2>(p) << std::endl;
std::cout << p << std::endl;
BOOST_TEST(p == make_vector(123, 456));
BOOST_TEST(p == make_vector(123, 456, 789));
}
#endif