Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84224 - trunk/libs/variant/test
From: antoshkka_at_[hidden]
Date: 2013-05-10 10:08:49


Author: apolukhin
Date: 2013-05-10 10:08:49 EDT (Fri, 10 May 2013)
New Revision: 84224
URL: http://svn.boost.org/trac/boost/changeset/84224

Log:
Added one more test for multivisitors that will be used as an example in documentation (refs #8459)
Text files modified:
   trunk/libs/variant/test/variant_multivisit_test.cpp | 23 +++++++++++++++++++++++
   1 files changed, 23 insertions(+), 0 deletions(-)

Modified: trunk/libs/variant/test/variant_multivisit_test.cpp
==============================================================================
--- trunk/libs/variant/test/variant_multivisit_test.cpp (original)
+++ trunk/libs/variant/test/variant_multivisit_test.cpp 2013-05-10 10:08:49 EDT (Fri, 10 May 2013)
@@ -64,6 +64,21 @@
     }
 };
 
+typedef boost::variant<int, double, bool> bool_like_t;
+typedef boost::variant<int, double> arithmetics_t;
+
+struct if_visitor: public boost::static_visitor<arithmetics_t> {
+ template <class T1, class T2>
+ arithmetics_t operator()(bool b, T1 v1, T2 v2) const {
+ if (b) {
+ return v1;
+ } else {
+ return v2;
+ }
+ }
+};
+
+
 int test_main(int , char* [])
 {
     test_visitor v;
@@ -89,5 +104,13 @@
     boost::apply_visitor(test_visitor(), v_array6[0], v_array6[1], v_array6[2], v_array6[3], v_array6[4]);
 #endif
 
+ bool_like_t v0(1), v1(true), v2(1.0);
+
+ BOOST_CHECK(
+ boost::apply_visitor(if_visitor(), v0, v1, v2)
+ ==
+ arithmetics_t(true)
+ );
+
     return boost::exit_success;
 }


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