mirror of
https://github.com/boostorg/fusion.git
synced 2025-07-21 08:12:39 +02:00
adapt template classes/structs
[SVN r59846]
This commit is contained in:
136
test/sequence/adapt_assoc_class.cpp
Normal file
136
test/sequence/adapt_assoc_class.cpp
Normal file
@ -0,0 +1,136 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2010 Christopher Schmidt
|
||||
|
||||
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 <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/sequence.hpp>
|
||||
#include <boost/fusion/support.hpp>
|
||||
#include <boost/fusion/container/list.hpp>
|
||||
#include <boost/fusion/container/vector.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/adapted/class/adapt_assoc_class.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/mpl/front.hpp>
|
||||
#include <boost/mpl/is_sequence.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace ns
|
||||
{
|
||||
struct x_member;
|
||||
struct y_member;
|
||||
struct z_member;
|
||||
|
||||
class point
|
||||
{
|
||||
public:
|
||||
|
||||
point() : x(0), y(0) {}
|
||||
point(int x, int y) : x(x), y(y) {}
|
||||
|
||||
int get_x() const { return x; }
|
||||
int get_y() const { return y; }
|
||||
void set_x(int x_) { x = x_; }
|
||||
void set_y(int y_) { y = y_; }
|
||||
|
||||
private:
|
||||
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_FUSION_ADAPT_ASSOC_CLASS(
|
||||
ns::point,
|
||||
(int, int, obj.get_x(), obj.set_x(val), ns::x_member)
|
||||
(int, int, obj.get_y(), obj.set_y(val), ns::y_member)
|
||||
)
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace boost::fusion;
|
||||
using namespace std;
|
||||
|
||||
std::cout << tuple_open('[');
|
||||
std::cout << tuple_close(']');
|
||||
std::cout << tuple_delimiter(", ");
|
||||
|
||||
{
|
||||
BOOST_MPL_ASSERT_NOT((traits::is_view<ns::point>));
|
||||
ns::point p(123, 456);
|
||||
|
||||
std::cout << at_c<0>(p) << std::endl;
|
||||
std::cout << at_c<1>(p) << std::endl;
|
||||
std::cout << p << std::endl;
|
||||
BOOST_TEST(p == make_vector(123, 456));
|
||||
|
||||
at_c<0>(p) = 6;
|
||||
at_c<1>(p) = 9;
|
||||
BOOST_TEST(p == make_vector(6, 9));
|
||||
|
||||
BOOST_STATIC_ASSERT(result_of::size<ns::point>::value == 2);
|
||||
BOOST_STATIC_ASSERT(!result_of::empty<ns::point>::value);
|
||||
|
||||
BOOST_TEST(front(p) == 6);
|
||||
BOOST_TEST(back(p) == 9);
|
||||
}
|
||||
|
||||
{
|
||||
boost::fusion::vector<int, float> v1(4, 2);
|
||||
ns::point v2(5, 3);
|
||||
boost::fusion::vector<long, double> v3(5, 4);
|
||||
BOOST_TEST(v1 < v2);
|
||||
BOOST_TEST(v1 <= v2);
|
||||
BOOST_TEST(v2 > v1);
|
||||
BOOST_TEST(v2 >= v1);
|
||||
BOOST_TEST(v2 < v3);
|
||||
BOOST_TEST(v2 <= v3);
|
||||
BOOST_TEST(v3 > v2);
|
||||
BOOST_TEST(v3 >= v2);
|
||||
}
|
||||
|
||||
{
|
||||
// conversion from ns::point to vector
|
||||
ns::point p(5, 3);
|
||||
boost::fusion::vector<int, short> v(p);
|
||||
v = p;
|
||||
}
|
||||
|
||||
{
|
||||
// conversion from ns::point to list
|
||||
ns::point p(5, 3);
|
||||
boost::fusion::list<int, short> l(p);
|
||||
l = p;
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_MPL_ASSERT((boost::mpl::is_sequence<ns::point>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<
|
||||
boost::fusion::result_of::value_at_c<ns::point,0>::type
|
||||
, boost::mpl::front<ns::point>::type>));
|
||||
}
|
||||
|
||||
{
|
||||
// assoc stuff
|
||||
BOOST_MPL_ASSERT((result_of::has_key<ns::point, ns::x_member>));
|
||||
BOOST_MPL_ASSERT((result_of::has_key<ns::point, ns::y_member>));
|
||||
BOOST_MPL_ASSERT((boost::mpl::not_<result_of::has_key<ns::point, ns::z_member> >));
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<ns::point, ns::x_member>::type, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<ns::point, ns::y_member>::type, int>));
|
||||
|
||||
ns::point p(5, 3);
|
||||
|
||||
BOOST_TEST(at_key<ns::x_member>(p) == 5);
|
||||
BOOST_TEST(at_key<ns::y_member>(p) == 3);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
142
test/sequence/adapt_assoc_class_named.cpp
Normal file
142
test/sequence/adapt_assoc_class_named.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2010 Christopher Schmidt
|
||||
|
||||
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 <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/sequence.hpp>
|
||||
#include <boost/fusion/support.hpp>
|
||||
#include <boost/fusion/container/list.hpp>
|
||||
#include <boost/fusion/container/vector.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/adapted/class/adapt_assoc_class_named.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/mpl/front.hpp>
|
||||
#include <boost/mpl/is_sequence.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace ns
|
||||
{
|
||||
struct x_member;
|
||||
struct y_member;
|
||||
struct z_member;
|
||||
|
||||
class point
|
||||
{
|
||||
public:
|
||||
|
||||
point() : x(0), y(0) {}
|
||||
point(int x, int y) : x(x), y(y) {}
|
||||
|
||||
int get_x() const { return x; }
|
||||
int get_y() const { return y; }
|
||||
void set_x(int x_) { x = x_; }
|
||||
void set_y(int y_) { y = y_; }
|
||||
|
||||
private:
|
||||
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_FUSION_ADAPT_ASSOC_CLASS_NAMED(
|
||||
ns::point,
|
||||
point,
|
||||
(int, int, obj.obj.get_x(), obj.obj.set_x(val), ns::x_member)
|
||||
(int, int, obj.obj.get_y(), obj.obj.set_y(val), ns::y_member)
|
||||
)
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace boost::fusion;
|
||||
using namespace std;
|
||||
|
||||
std::cout << tuple_open('[');
|
||||
std::cout << tuple_close(']');
|
||||
std::cout << tuple_delimiter(", ");
|
||||
|
||||
{
|
||||
BOOST_MPL_ASSERT_NOT((traits::is_view<adapted::point>));
|
||||
ns::point basep(123, 456);
|
||||
adapted::point p(basep);
|
||||
|
||||
std::cout << at_c<0>(p) << std::endl;
|
||||
std::cout << at_c<1>(p) << std::endl;
|
||||
std::cout << p << std::endl;
|
||||
BOOST_TEST(p == make_vector(123, 456));
|
||||
|
||||
at_c<0>(p) = 6;
|
||||
at_c<1>(p) = 9;
|
||||
BOOST_TEST(p == make_vector(6, 9));
|
||||
|
||||
BOOST_STATIC_ASSERT(result_of::size<adapted::point>::value == 2);
|
||||
BOOST_STATIC_ASSERT(!result_of::empty<adapted::point>::value);
|
||||
|
||||
BOOST_TEST(front(p) == 6);
|
||||
BOOST_TEST(back(p) == 9);
|
||||
}
|
||||
|
||||
{
|
||||
boost::fusion::vector<int, float> v1(4, 2);
|
||||
ns::point basev2(5, 3);
|
||||
adapted::point v2(basev2);
|
||||
boost::fusion::vector<long, double> v3(5, 4);
|
||||
BOOST_TEST(v1 < v2);
|
||||
BOOST_TEST(v1 <= v2);
|
||||
BOOST_TEST(v2 > v1);
|
||||
BOOST_TEST(v2 >= v1);
|
||||
BOOST_TEST(v2 < v3);
|
||||
BOOST_TEST(v2 <= v3);
|
||||
BOOST_TEST(v3 > v2);
|
||||
BOOST_TEST(v3 >= v2);
|
||||
}
|
||||
|
||||
{
|
||||
// conversion from adapted::point to vector
|
||||
ns::point basep(5, 3);
|
||||
adapted::point p(basep);
|
||||
boost::fusion::vector<int, short> v(p);
|
||||
v = p;
|
||||
}
|
||||
|
||||
{
|
||||
// conversion from adated::point to list
|
||||
ns::point basep(5, 3);
|
||||
adapted::point p(basep);
|
||||
boost::fusion::list<int, short> l(p);
|
||||
l = p;
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_MPL_ASSERT((boost::mpl::is_sequence<adapted::point>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<
|
||||
boost::fusion::result_of::value_at_c<adapted::point,0>::type
|
||||
, boost::mpl::front<adapted::point>::type>));
|
||||
}
|
||||
|
||||
{
|
||||
// assoc stuff
|
||||
BOOST_MPL_ASSERT((result_of::has_key<adapted::point, ns::x_member>));
|
||||
BOOST_MPL_ASSERT((result_of::has_key<adapted::point, ns::y_member>));
|
||||
BOOST_MPL_ASSERT((boost::mpl::not_<result_of::has_key<adapted::point, ns::z_member> >));
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<adapted::point, ns::x_member>::type, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<adapted::point, ns::y_member>::type, int>));
|
||||
|
||||
ns::point basep(5, 3);
|
||||
adapted::point p(basep);
|
||||
|
||||
BOOST_TEST(at_key<ns::x_member>(p) == 5);
|
||||
BOOST_TEST(at_key<ns::y_member>(p) == 3);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
121
test/sequence/adapt_assoc_struct_named.cpp
Normal file
121
test/sequence/adapt_assoc_struct_named.cpp
Normal file
@ -0,0 +1,121 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2010 Christopher Schmidt
|
||||
|
||||
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 <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/sequence.hpp>
|
||||
#include <boost/fusion/support.hpp>
|
||||
#include <boost/fusion/container/list.hpp>
|
||||
#include <boost/fusion/container/vector.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/adapted/struct/adapt_assoc_struct_named.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace ns
|
||||
{
|
||||
struct x_member;
|
||||
struct y_member;
|
||||
struct z_member;
|
||||
|
||||
struct point
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_FUSION_ADAPT_ASSOC_STRUCT_NAMED(
|
||||
ns::point,
|
||||
point,
|
||||
(int, x, ns::x_member)
|
||||
(int, y, ns::y_member)
|
||||
)
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace boost::fusion;
|
||||
|
||||
std::cout << tuple_open('[');
|
||||
std::cout << tuple_close(']');
|
||||
std::cout << tuple_delimiter(", ");
|
||||
|
||||
{
|
||||
BOOST_MPL_ASSERT_NOT((traits::is_view<adapted::point>));
|
||||
ns::point basep = {123, 456};
|
||||
adapted::point p(basep);
|
||||
|
||||
std::cout << at_c<0>(p) << std::endl;
|
||||
std::cout << at_c<1>(p) << std::endl;
|
||||
std::cout << p << std::endl;
|
||||
BOOST_TEST(p == make_vector(123, 456));
|
||||
|
||||
at_c<0>(p) = 6;
|
||||
at_c<1>(p) = 9;
|
||||
BOOST_TEST(p == make_vector(6, 9));
|
||||
|
||||
BOOST_STATIC_ASSERT(result_of::size<adapted::point>::value == 2);
|
||||
BOOST_STATIC_ASSERT(!result_of::empty<adapted::point>::value);
|
||||
|
||||
BOOST_TEST(front(p) == 6);
|
||||
BOOST_TEST(back(p) == 9);
|
||||
}
|
||||
|
||||
{
|
||||
vector<int, float> v1(4, 2);
|
||||
ns::point basev2 = {5, 3};
|
||||
adapted::point v2(basev2);
|
||||
|
||||
vector<long, double> v3(5, 4);
|
||||
BOOST_TEST(v1 < v2);
|
||||
BOOST_TEST(v1 <= v2);
|
||||
BOOST_TEST(v2 > v1);
|
||||
BOOST_TEST(v2 >= v1);
|
||||
BOOST_TEST(v2 < v3);
|
||||
BOOST_TEST(v2 <= v3);
|
||||
BOOST_TEST(v3 > v2);
|
||||
BOOST_TEST(v3 >= v2);
|
||||
}
|
||||
|
||||
{
|
||||
// conversion from adapted::point to vector
|
||||
ns::point basep = {5, 3};
|
||||
adapted::point p(basep);
|
||||
vector<int, short> v(p);
|
||||
v = p;
|
||||
}
|
||||
|
||||
{
|
||||
// conversion from adapted::point to list
|
||||
ns::point basep = {5, 3};
|
||||
adapted::point p(basep);
|
||||
list<int, short> l(p);
|
||||
l = p;
|
||||
}
|
||||
|
||||
{
|
||||
// assoc stuff
|
||||
BOOST_MPL_ASSERT((result_of::has_key<adapted::point, ns::x_member>));
|
||||
BOOST_MPL_ASSERT((result_of::has_key<adapted::point, ns::y_member>));
|
||||
BOOST_MPL_ASSERT((boost::mpl::not_<result_of::has_key<adapted::point, ns::z_member> >));
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<adapted::point, ns::x_member>::type, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<adapted::point, ns::y_member>::type, int>));
|
||||
|
||||
ns::point basep = {5, 3};
|
||||
adapted::point p(basep);
|
||||
|
||||
BOOST_TEST(at_key<ns::x_member>(p) == 5);
|
||||
BOOST_TEST(at_key<ns::y_member>(p) == 3);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
140
test/sequence/adapt_assoc_tpl_class.cpp
Normal file
140
test/sequence/adapt_assoc_tpl_class.cpp
Normal file
@ -0,0 +1,140 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2010 Christopher Schmidt
|
||||
|
||||
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 <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/sequence.hpp>
|
||||
#include <boost/fusion/support.hpp>
|
||||
#include <boost/fusion/container/list.hpp>
|
||||
#include <boost/fusion/container/vector.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/adapted/class/adapt_assoc_class.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/mpl/front.hpp>
|
||||
#include <boost/mpl/is_sequence.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace ns
|
||||
{
|
||||
struct x_member;
|
||||
struct y_member;
|
||||
struct z_member;
|
||||
|
||||
template<typename X, typename Y>
|
||||
class point
|
||||
{
|
||||
public:
|
||||
|
||||
point() : x(0), y(0) {}
|
||||
point(X x, Y y) : x(x), y(y) {}
|
||||
|
||||
X get_x() const { return x; }
|
||||
Y get_y() const { return y; }
|
||||
void set_x(X x_) { x = x_; }
|
||||
void set_y(Y y_) { y = y_; }
|
||||
|
||||
private:
|
||||
|
||||
X x;
|
||||
Y y;
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_FUSION_ADAPT_ASSOC_TPL_CLASS(
|
||||
(X)(Y),
|
||||
(ns::point)(X)(Y),
|
||||
(X, X, obj.get_x(), obj.set_x(val), ns::x_member)
|
||||
(Y, Y, obj.get_y(), obj.set_y(val), ns::y_member)
|
||||
)
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace boost::fusion;
|
||||
using namespace std;
|
||||
|
||||
typedef ns::point<int,int> point;
|
||||
|
||||
std::cout << tuple_open('[');
|
||||
std::cout << tuple_close(']');
|
||||
std::cout << tuple_delimiter(", ");
|
||||
|
||||
{
|
||||
BOOST_MPL_ASSERT_NOT((traits::is_view<point>));
|
||||
point p(123, 456);
|
||||
|
||||
std::cout << at_c<0>(p) << std::endl;
|
||||
std::cout << at_c<1>(p) << std::endl;
|
||||
std::cout << p << std::endl;
|
||||
BOOST_TEST(p == make_vector(123, 456));
|
||||
|
||||
at_c<0>(p) = 6;
|
||||
at_c<1>(p) = 9;
|
||||
BOOST_TEST(p == make_vector(6, 9));
|
||||
|
||||
BOOST_STATIC_ASSERT(result_of::size<point>::value == 2);
|
||||
BOOST_STATIC_ASSERT(!result_of::empty<point>::value);
|
||||
|
||||
BOOST_TEST(front(p) == 6);
|
||||
BOOST_TEST(back(p) == 9);
|
||||
}
|
||||
|
||||
{
|
||||
boost::fusion::vector<int, float> v1(4, 2);
|
||||
point v2(5, 3);
|
||||
boost::fusion::vector<long, double> v3(5, 4);
|
||||
BOOST_TEST(v1 < v2);
|
||||
BOOST_TEST(v1 <= v2);
|
||||
BOOST_TEST(v2 > v1);
|
||||
BOOST_TEST(v2 >= v1);
|
||||
BOOST_TEST(v2 < v3);
|
||||
BOOST_TEST(v2 <= v3);
|
||||
BOOST_TEST(v3 > v2);
|
||||
BOOST_TEST(v3 >= v2);
|
||||
}
|
||||
|
||||
{
|
||||
// conversion from point to vector
|
||||
point p(5, 3);
|
||||
boost::fusion::vector<int, short> v(p);
|
||||
v = p;
|
||||
}
|
||||
|
||||
{
|
||||
// conversion from point to list
|
||||
point p(5, 3);
|
||||
boost::fusion::list<int, short> l(p);
|
||||
l = p;
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_MPL_ASSERT((boost::mpl::is_sequence<point>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<
|
||||
boost::fusion::result_of::value_at_c<point,0>::type
|
||||
, boost::mpl::front<point>::type>));
|
||||
}
|
||||
|
||||
{
|
||||
// assoc stuff
|
||||
BOOST_MPL_ASSERT((result_of::has_key<point, ns::x_member>));
|
||||
BOOST_MPL_ASSERT((result_of::has_key<point, ns::y_member>));
|
||||
BOOST_MPL_ASSERT((boost::mpl::not_<result_of::has_key<point, ns::z_member> >));
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<point, ns::x_member>::type, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<point, ns::y_member>::type, int>));
|
||||
|
||||
point p(5, 3);
|
||||
|
||||
BOOST_TEST(at_key<ns::x_member>(p) == 5);
|
||||
BOOST_TEST(at_key<ns::y_member>(p) == 3);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
133
test/sequence/adapt_assoc_tpl_struct.cpp
Normal file
133
test/sequence/adapt_assoc_tpl_struct.cpp
Normal file
@ -0,0 +1,133 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2010 Christopher Schmidt
|
||||
|
||||
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 <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/adapted/struct/adapt_assoc_struct.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/at.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/size.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/empty.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/front.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/back.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/has_key.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/at_key.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/value_at_key.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/container/list/list.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/container/vector/convert.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
#include <boost/fusion/sequence/comparison/not_equal_to.hpp>
|
||||
#include <boost/fusion/sequence/comparison/less.hpp>
|
||||
#include <boost/fusion/sequence/comparison/less_equal.hpp>
|
||||
#include <boost/fusion/sequence/comparison/greater.hpp>
|
||||
#include <boost/fusion/sequence/comparison/greater_equal.hpp>
|
||||
#include <boost/fusion/support/is_view.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace ns
|
||||
{
|
||||
struct x_member;
|
||||
struct y_member;
|
||||
struct z_member;
|
||||
|
||||
template<typename X, typename Y>
|
||||
struct point
|
||||
{
|
||||
X x;
|
||||
Y y;
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_FUSION_ADAPT_ASSOC_TPL_STRUCT(
|
||||
(X)(Y),
|
||||
(ns::point)(X)(Y),
|
||||
(int, x, ns::x_member)
|
||||
(int, y, ns::y_member)
|
||||
)
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace boost::fusion;
|
||||
|
||||
typedef ns::point<int,int> point;
|
||||
|
||||
std::cout << tuple_open('[');
|
||||
std::cout << tuple_close(']');
|
||||
std::cout << tuple_delimiter(", ");
|
||||
|
||||
{
|
||||
BOOST_MPL_ASSERT_NOT((traits::is_view<point>));
|
||||
point p = {123, 456};
|
||||
|
||||
std::cout << at_c<0>(p) << std::endl;
|
||||
std::cout << at_c<1>(p) << std::endl;
|
||||
std::cout << p << std::endl;
|
||||
BOOST_TEST(p == make_vector(123, 456));
|
||||
|
||||
at_c<0>(p) = 6;
|
||||
at_c<1>(p) = 9;
|
||||
BOOST_TEST(p == make_vector(6, 9));
|
||||
|
||||
BOOST_STATIC_ASSERT(result_of::size<point>::value == 2);
|
||||
BOOST_STATIC_ASSERT(!result_of::empty<point>::value);
|
||||
|
||||
BOOST_TEST(front(p) == 6);
|
||||
BOOST_TEST(back(p) == 9);
|
||||
}
|
||||
|
||||
{
|
||||
vector<int, float> v1(4, 2);
|
||||
point v2 = {5, 3};
|
||||
vector<long, double> v3(5, 4);
|
||||
BOOST_TEST(v1 < v2);
|
||||
BOOST_TEST(v1 <= v2);
|
||||
BOOST_TEST(v2 > v1);
|
||||
BOOST_TEST(v2 >= v1);
|
||||
BOOST_TEST(v2 < v3);
|
||||
BOOST_TEST(v2 <= v3);
|
||||
BOOST_TEST(v3 > v2);
|
||||
BOOST_TEST(v3 >= v2);
|
||||
}
|
||||
|
||||
{
|
||||
// conversion from point to vector
|
||||
point p = {5, 3};
|
||||
vector<int, short> v(p);
|
||||
v = p;
|
||||
}
|
||||
|
||||
{
|
||||
// conversion from point to list
|
||||
point p = {5, 3};
|
||||
list<int, short> l(p);
|
||||
l = p;
|
||||
}
|
||||
|
||||
{
|
||||
// assoc stuff
|
||||
BOOST_MPL_ASSERT((result_of::has_key<point, ns::x_member>));
|
||||
BOOST_MPL_ASSERT((result_of::has_key<point, ns::y_member>));
|
||||
BOOST_MPL_ASSERT((boost::mpl::not_<result_of::has_key<point, ns::z_member> >));
|
||||
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<point, ns::x_member>::type, int>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<point, ns::y_member>::type, int>));
|
||||
|
||||
point p = {5, 3};
|
||||
|
||||
BOOST_TEST(at_key<ns::x_member>(p) == 5);
|
||||
BOOST_TEST(at_key<ns::y_member>(p) == 3);
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
133
test/sequence/adapt_tpl_class.cpp
Normal file
133
test/sequence/adapt_tpl_class.cpp
Normal file
@ -0,0 +1,133 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2009 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)
|
||||
==============================================================================*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/adapted/class/adapt_class.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/at.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/size.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/empty.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/front.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/back.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/value_at.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/container/list/list.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/container/vector/convert.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
#include <boost/fusion/sequence/comparison/not_equal_to.hpp>
|
||||
#include <boost/fusion/sequence/comparison/less.hpp>
|
||||
#include <boost/fusion/sequence/comparison/less_equal.hpp>
|
||||
#include <boost/fusion/sequence/comparison/greater.hpp>
|
||||
#include <boost/fusion/sequence/comparison/greater_equal.hpp>
|
||||
#include <boost/fusion/mpl.hpp>
|
||||
#include <boost/fusion/support/is_view.hpp>
|
||||
#include <boost/mpl/front.hpp>
|
||||
#include <boost/mpl/is_sequence.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace ns
|
||||
{
|
||||
template<typename X, typename Y>
|
||||
class point
|
||||
{
|
||||
public:
|
||||
|
||||
point() : x(0), y(0) {}
|
||||
point(X x, Y y) : x(x), y(y) {}
|
||||
|
||||
X get_x() const { return x; }
|
||||
Y get_y() const { return y; }
|
||||
void set_x(X x_) { x = x_; }
|
||||
void set_y(Y y_) { y = y_; }
|
||||
|
||||
private:
|
||||
|
||||
X x;
|
||||
Y y;
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_FUSION_ADAPT_TPL_CLASS(
|
||||
(X)(Y),
|
||||
(ns::point)(X)(Y),
|
||||
(X, X, obj.get_x(), obj.set_x(val))
|
||||
(Y, Y, obj.get_y(), obj.set_y(val))
|
||||
)
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace boost::fusion;
|
||||
using namespace std;
|
||||
|
||||
typedef ns::point<int, int> point;
|
||||
|
||||
std::cout << tuple_open('[');
|
||||
std::cout << tuple_close(']');
|
||||
std::cout << tuple_delimiter(", ");
|
||||
|
||||
{
|
||||
BOOST_MPL_ASSERT_NOT((traits::is_view<point>));
|
||||
point p(123, 456);
|
||||
|
||||
std::cout << at_c<0>(p) << std::endl;
|
||||
std::cout << at_c<1>(p) << std::endl;
|
||||
std::cout << p << std::endl;
|
||||
BOOST_TEST(p == make_vector(123, 456));
|
||||
|
||||
at_c<0>(p) = 6;
|
||||
at_c<1>(p) = 9;
|
||||
BOOST_TEST(p == make_vector(6, 9));
|
||||
|
||||
BOOST_STATIC_ASSERT(result_of::size<point>::value == 2);
|
||||
BOOST_STATIC_ASSERT(!result_of::empty<point>::value);
|
||||
|
||||
BOOST_TEST(front(p) == 6);
|
||||
BOOST_TEST(back(p) == 9);
|
||||
}
|
||||
|
||||
{
|
||||
boost::fusion::vector<int, float> v1(4, 2);
|
||||
point v2(5, 3);
|
||||
boost::fusion::vector<long, double> v3(5, 4);
|
||||
BOOST_TEST(v1 < v2);
|
||||
BOOST_TEST(v1 <= v2);
|
||||
BOOST_TEST(v2 > v1);
|
||||
BOOST_TEST(v2 >= v1);
|
||||
BOOST_TEST(v2 < v3);
|
||||
BOOST_TEST(v2 <= v3);
|
||||
BOOST_TEST(v3 > v2);
|
||||
BOOST_TEST(v3 >= v2);
|
||||
}
|
||||
|
||||
{
|
||||
// conversion from point to vector
|
||||
point p(5, 3);
|
||||
boost::fusion::vector<int, short> v(p);
|
||||
v = p;
|
||||
}
|
||||
|
||||
{
|
||||
// conversion from point to list
|
||||
point p(5, 3);
|
||||
boost::fusion::list<int, short> l(p);
|
||||
l = p;
|
||||
}
|
||||
|
||||
{
|
||||
BOOST_MPL_ASSERT((boost::mpl::is_sequence<point>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<
|
||||
boost::fusion::result_of::value_at_c<point,0>::type
|
||||
, boost::mpl::front<point>::type>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
122
test/sequence/adapt_tpl_struct.cpp
Normal file
122
test/sequence/adapt_tpl_struct.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2001-2007 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)
|
||||
==============================================================================*/
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/at.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/size.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/empty.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/front.hpp>
|
||||
#include <boost/fusion/sequence/intrinsic/back.hpp>
|
||||
#include <boost/fusion/sequence/io/out.hpp>
|
||||
#include <boost/fusion/container/vector/vector.hpp>
|
||||
#include <boost/fusion/container/list/list.hpp>
|
||||
#include <boost/fusion/container/generation/make_vector.hpp>
|
||||
#include <boost/fusion/container/vector/convert.hpp>
|
||||
#include <boost/fusion/sequence/comparison/equal_to.hpp>
|
||||
#include <boost/fusion/sequence/comparison/not_equal_to.hpp>
|
||||
#include <boost/fusion/sequence/comparison/less.hpp>
|
||||
#include <boost/fusion/sequence/comparison/less_equal.hpp>
|
||||
#include <boost/fusion/sequence/comparison/greater.hpp>
|
||||
#include <boost/fusion/sequence/comparison/greater_equal.hpp>
|
||||
#include <boost/fusion/support/is_view.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
namespace ns
|
||||
{
|
||||
template<typename X, typename Y>
|
||||
struct point
|
||||
{
|
||||
X x;
|
||||
Y y;
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_FUSION_ADAPT_TPL_STRUCT(
|
||||
(X)(Y),
|
||||
(ns::point)(X)(Y),
|
||||
(X, x)
|
||||
(Y, y)
|
||||
)
|
||||
|
||||
template<typename M>
|
||||
struct s { M m; };
|
||||
BOOST_FUSION_ADAPT_TPL_STRUCT((M), (s)(M), (M, m))
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
using namespace boost::fusion;
|
||||
|
||||
typedef ns::point<int, int> point;
|
||||
|
||||
std::cout << tuple_open('[');
|
||||
std::cout << tuple_close(']');
|
||||
std::cout << tuple_delimiter(", ");
|
||||
|
||||
{
|
||||
BOOST_MPL_ASSERT_NOT((traits::is_view<point>));
|
||||
point p = {123, 456};
|
||||
|
||||
std::cout << at_c<0>(p) << std::endl;
|
||||
std::cout << at_c<1>(p) << std::endl;
|
||||
std::cout << p << std::endl;
|
||||
BOOST_TEST(p == make_vector(123, 456));
|
||||
|
||||
at_c<0>(p) = 6;
|
||||
at_c<1>(p) = 9;
|
||||
BOOST_TEST(p == make_vector(6, 9));
|
||||
|
||||
BOOST_STATIC_ASSERT(result_of::size<point>::value == 2);
|
||||
BOOST_STATIC_ASSERT(!result_of::empty<point>::value);
|
||||
|
||||
BOOST_TEST(front(p) == 6);
|
||||
BOOST_TEST(back(p) == 9);
|
||||
}
|
||||
|
||||
{
|
||||
vector<int, float> v1(4, 2);
|
||||
point v2 = {5, 3};
|
||||
vector<long, double> v3(5, 4);
|
||||
BOOST_TEST(v1 < v2);
|
||||
BOOST_TEST(v1 <= v2);
|
||||
BOOST_TEST(v2 > v1);
|
||||
BOOST_TEST(v2 >= v1);
|
||||
BOOST_TEST(v2 < v3);
|
||||
BOOST_TEST(v2 <= v3);
|
||||
BOOST_TEST(v3 > v2);
|
||||
BOOST_TEST(v3 >= v2);
|
||||
}
|
||||
|
||||
{
|
||||
// conversion from point to vector
|
||||
point p = {5, 3};
|
||||
vector<int, short> v(p);
|
||||
v = p;
|
||||
}
|
||||
|
||||
{
|
||||
// conversion from point to list
|
||||
point p = {5, 3};
|
||||
list<int, short> l(p);
|
||||
l = p;
|
||||
}
|
||||
|
||||
{ // begin/end
|
||||
using namespace boost::fusion;
|
||||
|
||||
typedef result_of::begin<s<int> >::type b;
|
||||
typedef result_of::end<s<int> >::type e;
|
||||
// this fails
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::next<b>::type, e>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
Reference in New Issue
Block a user