Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r74906 - in trunk/libs/spirit/test: karma qi
From: joel_at_[hidden]
Date: 2011-10-10 20:24:05


Author: djowel
Date: 2011-10-10 20:24:04 EDT (Mon, 10 Oct 2011)
New Revision: 74906
URL: http://svn.boost.org/trac/boost/changeset/74906

Log:
Added rvalue support for symbols %=
Text files modified:
   trunk/libs/spirit/test/karma/symbols2.cpp | 28 +++++++++++++++++++---------
   trunk/libs/spirit/test/qi/symbols2.cpp | 38 ++++++++++++++++++++++++++------------
   2 files changed, 45 insertions(+), 21 deletions(-)

Modified: trunk/libs/spirit/test/karma/symbols2.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/symbols2.cpp (original)
+++ trunk/libs/spirit/test/karma/symbols2.cpp 2011-10-10 20:24:04 EDT (Mon, 10 Oct 2011)
@@ -1,6 +1,6 @@
 // Copyright (c) 2001-2011 Hartmut Kaiser
-//
-// Distributed under the Boost Software License, Version 1.0. (See accompanying
+//
+// 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/config/warning_disable.hpp>
@@ -19,7 +19,7 @@
 namespace fusion = boost::fusion;
 
 template <typename T>
-inline std::vector<T>
+inline std::vector<T>
 make_vector(T const& t1, T const& t2)
 {
     std::vector<T> v;
@@ -45,7 +45,7 @@
         rule<output_iterator_type> r2 = lit("Hartmut");
         rule<output_iterator_type> r3 = lit("Tom");
         rule<output_iterator_type> r4 = lit("Kim");
-
+
         sym.add
             ('j', r1.alias())
             ('h', r2.alias())
@@ -53,11 +53,11 @@
             ('k', r4.alias())
         ;
 
- boost::mpl::true_ f =
+ boost::mpl::true_ f =
             boost::mpl::bool_<boost::spirit::traits::is_generator<
                 symbols<char, rule<output_iterator_type> > >::value>();
 
- // silence stupid compiler warnings
+ // silence stupid compiler warnings
         // i.e. MSVC warning C4189: 'f' : local variable is initialized but not referenced
         BOOST_TEST((f.value));
 
@@ -97,7 +97,7 @@
 
         symbols<char, rule<output_iterator_type, std::string()> > sym;
         rule<output_iterator_type, std::string()> r1 = string;
-
+
         sym.add
             ('j', r1.alias())
             ('h', r1.alias())
@@ -105,11 +105,11 @@
             ('k', r1.alias())
         ;
 
- boost::mpl::true_ f =
+ boost::mpl::true_ f =
             boost::mpl::bool_<boost::spirit::traits::is_generator<
                 symbols<char, std::string> >::value>();
 
- // silence stupid compiler warnings
+ // silence stupid compiler warnings
         // i.e. MSVC warning C4189: 'f' : local variable is initialized but not referenced
         BOOST_TEST((f.value));
 
@@ -140,5 +140,15 @@
         BOOST_TEST((!test("", sym, 'h')));
     }
 
+ { // test for proto problem with rvalue references (10-11-2011)
+ symbols<char, std::string> sym;
+
+ sym += std::make_pair('j', "Joel");
+ sym += std::make_pair('h', "Hartmut");
+
+ BOOST_TEST((test("Joel", sym, 'j')));
+ BOOST_TEST((test("Hartmut", sym, 'h')));
+ }
+
     return boost::report_errors();
 }

Modified: trunk/libs/spirit/test/qi/symbols2.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/symbols2.cpp (original)
+++ trunk/libs/spirit/test/qi/symbols2.cpp 2011-10-10 20:24:04 EDT (Mon, 10 Oct 2011)
@@ -31,6 +31,11 @@
     char str[2];
 };
 
+std::string get_str(char const* str)
+{
+ return std::string(str);
+}
+
 int
 main()
 {
@@ -124,12 +129,12 @@
         BOOST_TEST(i == 2);
         BOOST_TEST(!test("c", r(phx::ref(sym))));
     }
-
+
     { // find
-
+
         symbols<char, int> sym;
         sym.add("a", 1)("b", 2);
-
+
         BOOST_TEST(!sym.find("c"));
 
         BOOST_TEST(sym.find("a") && *sym.find("a") == 1);
@@ -142,14 +147,14 @@
         BOOST_TEST(sym.find("a") && *sym.find("a") == 1);
         BOOST_TEST(sym.find("b") && *sym.find("b") == 2);
         BOOST_TEST(sym.find("c") && *sym.find("c") == 0);
-
+
         symbols<char, int> const_sym(sym);
 
         BOOST_TEST(const_sym.find("a") && *const_sym.find("a") == 1);
         BOOST_TEST(const_sym.find("b") && *const_sym.find("b") == 2);
         BOOST_TEST(const_sym.find("c") && *const_sym.find("c") == 0);
         BOOST_TEST(!const_sym.find("d"));
-
+
         char const *str1 = "all";
         char const *first = str1, *last = str1 + 3;
         BOOST_TEST(*sym.prefix_find(first, last) == 1 && first == str1 + 1);
@@ -169,9 +174,9 @@
         symbols <char,int> sym3(sym);
         BOOST_TEST(sym3.name()=="test");
     }
-
+
     { // Substrings
-
+
         symbols<char, int> sym;
         BOOST_TEST(sym.at("foo") == 0);
         sym.at("foo") = 1;
@@ -184,10 +189,10 @@
         BOOST_TEST(!sym.find("foot"));
         BOOST_TEST(!sym.find("afoot"));
 
- char const *str, *first, *last;
+ char const *str, *first, *last;
         str = "foolish"; first = str; last = str + 7;
         BOOST_TEST(*sym.prefix_find(first, last) == 2 && first == str + 4);
-
+
         first = str; last = str + 4;
         BOOST_TEST(*sym.prefix_find(first, last) == 2 && first == str + 4);
 
@@ -200,13 +205,13 @@
         first = str; last = str + 2;
         BOOST_TEST(!sym.prefix_find(first, last) && first == str);
     }
-
+
     {
         // remove bug
-
+
         std::string s;
         symbols<char, double> vars;
-
+
         vars.add("l1", 12.0);
         vars.add("l2", 0.0);
         vars.remove("l2");
@@ -215,5 +220,14 @@
         BOOST_TEST(d != 0);
     }
 
+ { // test for proto problem with rvalue references (10-11-2011)
+ symbols<char, int> sym;
+ sym += get_str("Joel");
+ sym += get_str("Ruby");
+
+ BOOST_TEST((test("Joel", sym)));
+ BOOST_TEST((test("Ruby", sym)));
+ }
+
     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