|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55010 - trunk/boost/spirit/home/support
From: hartmut.kaiser_at_[hidden]
Date: 2009-07-17 23:39:04
Author: hkaiser
Date: 2009-07-17 23:39:03 EDT (Fri, 17 Jul 2009)
New Revision: 55010
URL: http://svn.boost.org/trac/boost/changeset/55010
Log:
Spirit: fixing inconsistency in list parser behavior for optional/variant based attributes
Text files modified:
trunk/boost/spirit/home/support/attributes.hpp | 19 ++++++++++++--
trunk/boost/spirit/home/support/container.hpp | 51 +++++++++++++++++++++++++++++++++++++--
2 files changed, 64 insertions(+), 6 deletions(-)
Modified: trunk/boost/spirit/home/support/attributes.hpp
==============================================================================
--- trunk/boost/spirit/home/support/attributes.hpp (original)
+++ trunk/boost/spirit/home/support/attributes.hpp 2009-07-17 23:39:03 EDT (Fri, 17 Jul 2009)
@@ -430,7 +430,7 @@
///////////////////////////////////////////////////////////////////////////
template <typename T>
struct is_container;
-
+
namespace detail
{
template <typename T>
@@ -438,14 +438,27 @@
{
val = T();
}
-
+
template <typename T>
void clear_impl(T& val, mpl::true_)
{
val.clear();
}
+
+ template <typename T>
+ void clear_impl(optional<T>& val, mpl::true_)
+ {
+ val = T();
+ }
+
+ template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
+ void clear_impl(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>& val
+ , mpl::true_)
+ {
+ val = T0();
+ }
}
-
+
template <typename T>
void clear(T& val)
{
Modified: trunk/boost/spirit/home/support/container.hpp
==============================================================================
--- trunk/boost/spirit/home/support/container.hpp (original)
+++ trunk/boost/spirit/home/support/container.hpp 2009-07-17 23:39:03 EDT (Fri, 17 Jul 2009)
@@ -57,7 +57,7 @@
/***/
template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
- struct is_container<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
+ struct is_container<variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
: mpl::bool_<BOOST_PP_REPEAT(BOOST_VARIANT_LIMIT_TYPES
, BOOST_SPIRIT_IS_CONTAINER, _) false> {};
@@ -79,10 +79,10 @@
// this will be instantiated if the variant holds a container
template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
- struct value<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
+ struct value<variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
{
typedef typename
- boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types
+ variant<BOOST_VARIANT_ENUM_PARAMS(T)>::types
types;
typedef typename
mpl::find_if<types, is_container<mpl::_1> >::type
@@ -166,6 +166,51 @@
c.push_back(val);
}
+ template <typename Container, typename T>
+ inline void push_back(optional<Container>& c, T const& val)
+ {
+ if (!c)
+ c = Container();
+ push_back(boost::get<Container>(c), val);
+ }
+
+ namespace detail
+ {
+ template <typename T>
+ struct push_back_visitor : public static_visitor<>
+ {
+ push_back_visitor(T const& t) : t_(t) {}
+
+ template <typename Container>
+ void push_back_impl(Container& c, mpl::true_) const
+ {
+ push_back(c, t_);
+ }
+
+ template <typename T_>
+ void push_back_impl(T_&, mpl::false_) const
+ {
+ // this variant doesn't hold a container
+ BOOST_ASSERT(false);
+ }
+
+ template <typename T_>
+ void operator()(T_& c) const
+ {
+ push_back_impl(c, typename is_container<T_>::type());
+ }
+
+ T const& t_;
+ };
+ }
+
+ template <BOOST_VARIANT_ENUM_PARAMS(typename T_), typename T>
+ inline void push_back(variant<BOOST_VARIANT_ENUM_PARAMS(T_)>& c
+ , T const& val)
+ {
+ apply_visitor(detail::push_back_visitor<T>(val), c);
+ }
+
template <typename Container>
inline void push_back(Container&, unused_type)
{
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