|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r49818 - trunk/libs/spirit/phoenix/test/bind
From: steven_at_[hidden]
Date: 2008-11-17 14:43:41
Author: steven_watanabe
Date: 2008-11-17 14:43:41 EST (Mon, 17 Nov 2008)
New Revision: 49818
URL: http://svn.boost.org/trac/boost/changeset/49818
Log:
More thorough tests for using bind with member variables
Text files modified:
trunk/libs/spirit/phoenix/test/bind/bind_member_variable_tests.cpp | 74 ++++++++++++++++++++++++++++++++++-----
1 files changed, 64 insertions(+), 10 deletions(-)
Modified: trunk/libs/spirit/phoenix/test/bind/bind_member_variable_tests.cpp
==============================================================================
--- trunk/libs/spirit/phoenix/test/bind/bind_member_variable_tests.cpp (original)
+++ trunk/libs/spirit/phoenix/test/bind/bind_member_variable_tests.cpp 2008-11-17 14:43:41 EST (Mon, 17 Nov 2008)
@@ -29,21 +29,75 @@
};
}
-int
-main()
+template<class T, class F>
+void write_test(F f) {
+ T x_;
+ bind(&T::m, f(x_))() = 122;
+ BOOST_TEST(x_.m == 122);
+ bind(&T::m, arg1)(f(x_)) = 123;
+ BOOST_TEST(x_.m == 123);
+}
+
+template<class T, class F>
+void read_test(F f) {
+ T x_;
+ x_.m = 123;
+
+ BOOST_TEST(bind(&T::m, f(x_))() == 123);
+ BOOST_TEST(bind(&T::m, arg1)(f(x_)) == 123);
+}
+
+struct identity
{
+ template<class T>
+ T& operator()(T& t) const
{
- test::x x_;
- bind(&test::x::m, x_)() = 123;
- bind(&test::x::m, arg1)(x_) = 123;
- BOOST_TEST(x_.m == 123);
+ return t;
}
+};
+
+struct constify
+{
+ template<class T>
+ const T& operator()(const T& t) const
{
- test::xx x_= {0};
- bind(&test::xx::m, val(x_))(); // does not compile
- bind(&test::xx::m, ref(x_))() = 1;
- bind(&test::xx::m, cref(x_))();
+ return t;
}
+};
+
+struct add_pointer
+{
+ template<class T>
+ T* const operator()(T& t) const
+ {
+ return &t;
+ }
+};
+
+struct add_const_pointer
+{
+ template<class T>
+ const T* const operator()(const T& t) const
+ {
+ return &t;
+ }
+};
+
+int
+main()
+{
+ write_test<test::x>(identity());
+ write_test<test::x>(add_pointer());
+ write_test<test::xx>(identity());
+ write_test<test::xx>(add_pointer());
+ read_test<test::x>(identity());
+ //read_test<test::x>(constify()); // this fails because of capture by value.
+ read_test<test::x>(add_pointer());
+ read_test<test::x>(add_const_pointer());
+ read_test<test::xx>(identity());
+ read_test<test::xx>(constify());
+ read_test<test::xx>(add_pointer());
+ read_test<test::xx>(add_const_pointer());
return boost::report_errors();
}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk