|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r74915 - in branches/release: . boost boost/spirit boost/spirit/home boost/spirit/home/karma boost/spirit/home/karma/string boost/spirit/home/qi/string libs libs/spirit libs/spirit/test libs/spirit/test/karma libs/spirit/test/qi
From: hartmut.kaiser_at_[hidden]
Date: 2011-10-11 07:30:21
Author: hkaiser
Date: 2011-10-11 07:30:19 EDT (Tue, 11 Oct 2011)
New Revision: 74915
URL: http://svn.boost.org/trac/boost/changeset/74915
Log:
Spirit: merging bugfix from trunk (caused by changes in proto)
Properties modified:
branches/release/ (props changed)
branches/release/boost/ (props changed)
branches/release/boost/spirit/ (props changed)
branches/release/boost/spirit/home/ (props changed)
branches/release/boost/spirit/home/karma/ (props changed)
branches/release/libs/ (props changed)
branches/release/libs/spirit/ (props changed)
branches/release/libs/spirit/test/ (props changed)
Text files modified:
branches/release/boost/spirit/home/karma/string/symbols.hpp | 47 +++++++++++++++++++++++++++------------
branches/release/boost/spirit/home/qi/string/symbols.hpp | 19 +++++++++++++++
branches/release/libs/spirit/test/karma/symbols2.cpp | 28 ++++++++++++++++-------
branches/release/libs/spirit/test/qi/symbols2.cpp | 38 ++++++++++++++++++++++----------
4 files changed, 95 insertions(+), 37 deletions(-)
Modified: branches/release/boost/spirit/home/karma/string/symbols.hpp
==============================================================================
--- branches/release/boost/spirit/home/karma/string/symbols.hpp (original)
+++ branches/release/boost/spirit/home/karma/string/symbols.hpp 2011-10-11 07:30:19 EDT (Tue, 11 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)
#if !defined(BOOST_SPIRIT_KARMA_SYMBOLS_NOV_23_2009_1251PM)
@@ -37,11 +37,11 @@
template <typename T, typename Attribute, typename Enable>
struct symbols_lookup
{
- typedef
+ typedef
mpl::eval_if<fusion::traits::is_sequence<T>
, traits::detail::value_at_c<T, 0>
, detail::add_const_ref<T> > sequence_type;
- typedef typename
+ typedef typename
mpl::eval_if<traits::is_container<T>
, traits::container_value<T>
, sequence_type>::type type;
@@ -90,11 +90,11 @@
template <typename Attribute, typename T, typename Enable>
struct symbols_value
{
- typedef
+ typedef
mpl::eval_if<fusion::traits::is_sequence<T>
, traits::detail::value_at_c<T, 1>
, mpl::identity<unused_type> > sequence_type;
- typedef typename
+ typedef typename
mpl::eval_if<traits::is_container<T>
, traits::container_value<T>
, sequence_type>::type type;
@@ -150,7 +150,7 @@
: mpl::if_<
traits::not_is_unused<T>
, std::map<Attribute, T>
- , std::set<Attribute>
+ , std::set<Attribute>
>
{};
@@ -161,7 +161,7 @@
template <typename CharEncoding, typename Tag>
struct generate_encoded
{
- typedef typename
+ typedef typename
proto::terminal<tag::char_code<Tag, CharEncoding> >::type
encoding_type;
@@ -298,6 +298,7 @@
return sym.remove(attr);
}
+#if defined(BOOST_NO_RVALUE_REFERENCES)
// non-const version needed to suppress proto's += kicking in
template <typename Attr, typename T_>
friend adder const&
@@ -313,7 +314,23 @@
{
return sym.remove(attr);
}
+#else
+ // for rvalue references
+ template <typename Attr, typename T_>
+ friend adder const&
+ operator+= (symbols& sym, std::pair<Attr, T_>&& p)
+ {
+ return sym.add(p.first, p.second);
+ }
+ // for rvalue references
+ template <typename Attr>
+ friend remover const&
+ operator-= (symbols& sym, Attr&& attr)
+ {
+ return sym.remove(attr);
+ }
+#endif
template <typename F>
void for_each(F f) const
{
@@ -346,7 +363,7 @@
return karma::detail::generate_encoded<CharEncoding, Tag>::call(
sink, (*it).second
- , traits::symbols_value<Attribute, Attr>::call(attr)) &&
+ , traits::symbols_value<Attribute, Attr>::call(attr)) &&
karma::delimit_out(sink, d);
}
@@ -586,7 +603,7 @@
value_type at(Attr const& attr)
{
typename Lookup::iterator it = lookup->find(attr);
- if (it == lookup->end())
+ if (it == lookup->end())
add(attr);
return unused;
}
@@ -605,7 +622,7 @@
return karma::detail::generate_encoded<CharEncoding, Tag>::
call(sink
, traits::symbols_lookup<Attr, Attribute>::call(attr)
- , unused) &&
+ , unused) &&
karma::delimit_out(sink, d);
}
@@ -706,13 +723,13 @@
reference<symbols<Attribute, T, Lookup, CharEnconding, Tag> >
, Modifiers>
{
- static bool const lower =
+ static bool const lower =
has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
- static bool const upper =
+ static bool const upper =
has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
typedef reference<
- symbols<Attribute, T, Lookup, CharEnconding, Tag>
+ symbols<Attribute, T, Lookup, CharEnconding, Tag>
> reference_;
typedef typename mpl::if_c<
@@ -740,7 +757,7 @@
, typename Attr, typename Context, typename Iterator>
struct handles_container<karma::symbols<Attribute, T, Lookup, CharEncoding, Tag>
, Attr, Context, Iterator>
- : traits::is_container<Attr> {};
+ : traits::is_container<Attr> {};
}}}
#if defined(BOOST_MSVC)
Modified: branches/release/boost/spirit/home/qi/string/symbols.hpp
==============================================================================
--- branches/release/boost/spirit/home/qi/string/symbols.hpp (original)
+++ branches/release/boost/spirit/home/qi/string/symbols.hpp 2011-10-11 07:30:19 EDT (Tue, 11 Oct 2011)
@@ -166,6 +166,7 @@
return sym.remove(str);
}
+#if defined(BOOST_NO_RVALUE_REFERENCES)
// non-const version needed to suppress proto's += kicking in
template <typename Str>
friend adder const&
@@ -181,7 +182,23 @@
{
return sym.remove(str);
}
+#else
+ // for rvalue references
+ template <typename Str>
+ friend adder const&
+ operator+=(symbols& sym, Str&& str)
+ {
+ return sym.add(str);
+ }
+ // for rvalue references
+ template <typename Str>
+ friend remover const&
+ operator-=(symbols& sym, Str&& str)
+ {
+ return sym.remove(str);
+ }
+#endif
template <typename F>
void for_each(F f) const
{
@@ -404,7 +421,7 @@
template <typename Char, typename T, typename Lookup, typename Filter
, typename Attr, typename Context, typename Iterator>
struct handles_container<qi::symbols<Char, T, Lookup, Filter>, Attr, Context, Iterator>
- : traits::is_container<Attr> {};
+ : traits::is_container<Attr> {};
}}}
#if defined(BOOST_MSVC)
Modified: branches/release/libs/spirit/test/karma/symbols2.cpp
==============================================================================
--- branches/release/libs/spirit/test/karma/symbols2.cpp (original)
+++ branches/release/libs/spirit/test/karma/symbols2.cpp 2011-10-11 07:30:19 EDT (Tue, 11 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: branches/release/libs/spirit/test/qi/symbols2.cpp
==============================================================================
--- branches/release/libs/spirit/test/qi/symbols2.cpp (original)
+++ branches/release/libs/spirit/test/qi/symbols2.cpp 2011-10-11 07:30:19 EDT (Tue, 11 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