|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r69022 - in trunk/boost/spirit/home: qi/detail support
From: joel_at_[hidden]
Date: 2011-02-19 04:14:35
Author: djowel
Date: 2011-02-19 04:14:26 EST (Sat, 19 Feb 2011)
New Revision: 69022
URL: http://svn.boost.org/trac/boost/changeset/69022
Log:
Tweaks. Allow attribute compatibility on alternatives
Text files modified:
trunk/boost/spirit/home/qi/detail/alternative_function.hpp | 30 ++++++++++++++----------------
trunk/boost/spirit/home/support/attributes.hpp | 23 +++++++++++++++++++++--
trunk/boost/spirit/home/support/attributes_fwd.hpp | 14 ++++++++++----
3 files changed, 45 insertions(+), 22 deletions(-)
Modified: trunk/boost/spirit/home/qi/detail/alternative_function.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/detail/alternative_function.hpp (original)
+++ trunk/boost/spirit/home/qi/detail/alternative_function.hpp 2011-02-19 04:14:26 EST (Sat, 19 Feb 2011)
@@ -65,9 +65,19 @@
template <typename Component>
bool call_optional_or_variant(Component const& component, mpl::true_) const
{
- // if Attribute is an optional, then create an attribute for
- // the Component with its expected type.
- typename traits::attribute_of<Component, Context, Iterator>::type val;
+ // If Attribute is an optional, then create an attribute for the Component
+ // with the type optional::value_type. If the expected attribute is unused type,
+ // use it instead.
+ typedef typename
+ traits::attribute_of<Component, Context, Iterator>::type
+ expected_type;
+
+ typename mpl::if_<
+ is_same<expected_type, unused_type>,
+ unused_type,
+ typename Attribute::value_type>::type
+ val;
+
if (component.parse(first, last, context, skipper, val))
{
traits::assign_to(val, attr);
@@ -79,18 +89,7 @@
template <typename Component>
bool call_optional_or_variant(Component const& component, mpl::false_) const
{
-#ifndef BOOST_SPIRIT_ALTERNATIVES_ALLOW_ATTR_COMPAT
- // if Attribute is a variant, then create an attribute for
- // the Component with its expected type.
- typename traits::attribute_of<Component, Context, Iterator>::type val;
- if (component.parse(first, last, context, skipper, val))
- {
- traits::assign_to(val, attr);
- return true;
- }
- return false;
-#else
- // if Attribute is a variant, then search the variant types for a
+ // If Attribute is a variant, then search the variant types for a
// suitable substitute type.
typename
@@ -105,7 +104,6 @@
return true;
}
return false;
-#endif
}
template <typename Component>
Modified: trunk/boost/spirit/home/support/attributes.hpp
==============================================================================
--- trunk/boost/spirit/home/support/attributes.hpp (original)
+++ trunk/boost/spirit/home/support/attributes.hpp 2011-02-19 04:14:26 EST (Sat, 19 Feb 2011)
@@ -58,8 +58,8 @@
// components.
///////////////////////////////////////////////////////////////////////////
- // Find out if T is a substitute for Expected attribute
- template <typename T, typename Expected, typename Enable = void>
+ // Find out if T can be a substitute for Expected attribute
+ template <typename T, typename Expected, typename Enable /*= void*/>
struct is_substitute : is_same<T, Expected> {};
template <typename T, typename Expected>
@@ -77,6 +77,25 @@
>::type>
: mpl::true_ {};
+ namespace detail
+ {
+ template <typename T, typename Expected>
+ struct value_type_is_substitute
+ : is_substitute<typename T::value_type, typename Expected::value_type>
+ {};
+ }
+
+ template <typename T, typename Expected>
+ struct is_substitute<T, Expected,
+ typename enable_if<
+ mpl::and_<
+ is_container<T>,
+ is_container<Expected>,
+ detail::value_type_is_substitute<T, Expected>
+ >
+ >::type>
+ : mpl::true_ {};
+
template <typename T, typename Enable/* = void*/>
struct is_proxy : mpl::false_ {};
Modified: trunk/boost/spirit/home/support/attributes_fwd.hpp
==============================================================================
--- trunk/boost/spirit/home/support/attributes_fwd.hpp (original)
+++ trunk/boost/spirit/home/support/attributes_fwd.hpp 2011-02-19 04:14:26 EST (Sat, 19 Feb 2011)
@@ -50,6 +50,12 @@
namespace boost { namespace spirit { namespace traits
{
///////////////////////////////////////////////////////////////////////////
+ // Find out if T can be a substitute for Expected attribute
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename T, typename Expected, typename Enable = void>
+ struct is_substitute;
+
+ ///////////////////////////////////////////////////////////////////////////
// Determine if T is a proxy
///////////////////////////////////////////////////////////////////////////
template <typename T, typename Enable = void>
@@ -63,7 +69,7 @@
///////////////////////////////////////////////////////////////////////////
template <typename Attribute, typename Enable = void>
struct attribute_type;
-
+
///////////////////////////////////////////////////////////////////////////
// Retrieve the size of a fusion sequence (compile time)
///////////////////////////////////////////////////////////////////////////
@@ -152,7 +158,7 @@
template <typename T, typename Attribute>
typename spirit::result_of::attribute_as<T, Attribute>::type
as(Attribute const& attr);
-
+
template <typename T, typename Attribute>
bool valid_as(Attribute const& attr);
@@ -194,7 +200,7 @@
template <typename T, typename Enable = void>
struct is_container;
-
+
template <typename T, typename Enable = void>
struct is_iterator_range;
@@ -263,7 +269,7 @@
///////////////////////////////////////////////////////////////////////////
// transform attribute types exposed from compound operator components
- ///////////////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////////////
template <typename Attribute, typename Domain>
struct alternative_attribute_transform;
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