$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r61323 - in trunk/boost/spirit/home: karma/string support
From: hartmut.kaiser_at_[hidden]
Date: 2010-04-16 14:13:37
Author: hkaiser
Date: 2010-04-16 14:13:37 EDT (Fri, 16 Apr 2010)
New Revision: 61323
URL: http://svn.boost.org/trac/boost/changeset/61323
Log:
Spirit: extended attribute handling capabilities of the karma::symbols generator
Text files modified: 
   trunk/boost/spirit/home/karma/string/symbols.hpp |    49 ++++++++++++++++++++++----------------- 
   trunk/boost/spirit/home/support/attributes.hpp   |    12 ++++++++-                               
   2 files changed, 38 insertions(+), 23 deletions(-)
Modified: trunk/boost/spirit/home/karma/string/symbols.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/string/symbols.hpp	(original)
+++ trunk/boost/spirit/home/karma/string/symbols.hpp	2010-04-16 14:13:37 EDT (Fri, 16 Apr 2010)
@@ -30,22 +30,7 @@
 ///////////////////////////////////////////////////////////////////////////////
 namespace boost { namespace spirit { namespace traits
 {
-    namespace detail
-    {
-        ///////////////////////////////////////////////////////////////////////
-        // extract first and second element of a fusion sequence
-        template <typename T>
-        struct add_const_ref 
-          : add_reference<typename add_const<T>::type> 
-        {};
-
-        template <typename T, int N>
-        struct value_at_c 
-          : add_const_ref<typename fusion::result_of::value_at_c<T, N>::type> 
-        {};
-    }
-
-    template <typename T, typename Attribute, typename Enable = void>
+    template <typename Attribute, typename T, typename Enable = void>
     struct symbols_lookup
     {
         typedef 
@@ -87,7 +72,18 @@
         }
     };
 
-    template <typename T, typename Attribute, typename Enable = void>
+    template <typename Attribute>
+    struct symbols_lookup<Attribute, Attribute>
+    {
+        typedef Attribute const& type;
+
+        static type call(Attribute const& t)
+        {
+            return t;
+        }
+    };
+
+    template <typename Attribute, typename T, typename Enable = void>
     struct symbols_value
     {
         typedef 
@@ -128,6 +124,17 @@
             return call(t, is_container(), is_sequence());
         }
     };
+
+    template <typename Attribute>
+    struct symbols_value<Attribute, Attribute>
+    {
+        typedef unused_type type;
+
+        static type call(Attribute const&)
+        {
+            return unused;
+        }
+    };
 }}}
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -322,13 +329,13 @@
           , Attr const& attr) const
         {
             typename Lookup::iterator it = lookup->find(
-                traits::symbols_lookup<Attr, Attribute>::call(attr));
+                traits::symbols_lookup<Attribute, Attr>::call(attr));
             if (it == lookup->end())
                 return false;
 
             return karma::detail::generate_encoded<CharEncoding, Tag>::call(
                         sink, (*it).second
-                      , traits::symbols_value<Attr, Attribute>::call(attr)) && 
+                      , traits::symbols_value<Attribute, Attr>::call(attr)) && 
                    karma::delimit_out(sink, d);
         }
 
@@ -563,13 +570,13 @@
           , Attr const& attr) const
         {
             typename Lookup::iterator it = lookup->find(
-                traits::symbols_lookup<Attr, Attribute>::call(attr));
+                traits::symbols_lookup<Attribute, Attr>::call(attr));
             if (it == lookup->end())
                 return false;
 
             return karma::detail::generate_encoded<CharEncoding, Tag>::
                       call(sink
-                        , traits::symbols_lookup<Attr, Attribute>::call(attr)
+                        , traits::symbols_lookup<Attribute, Attr>::call(attr)
                         , unused) && 
                    karma::delimit_out(sink, d);
         }
Modified: trunk/boost/spirit/home/support/attributes.hpp
==============================================================================
--- trunk/boost/spirit/home/support/attributes.hpp	(original)
+++ trunk/boost/spirit/home/support/attributes.hpp	2010-04-16 14:13:37 EDT (Fri, 16 Apr 2010)
@@ -40,6 +40,7 @@
 #include <boost/mpl/deref.hpp>
 #include <boost/mpl/distance.hpp>
 #include <boost/mpl/or.hpp>
+#include <boost/mpl/has_xxx.hpp>
 #include <boost/proto/proto_fwd.hpp>
 #include <boost/utility/enable_if.hpp>
 #include <boost/variant.hpp>
@@ -120,7 +121,8 @@
         {};
     }
 
-    template <typename Expected, typename Attribute, typename IsNotVariant = mpl::false_>
+    template <typename Expected, typename Attribute
+      , typename IsNotVariant = mpl::false_, typename Enable = void>
     struct compute_compatible_component_variant
       : mpl::or_<
             traits::detail::attribute_is_compatible<Expected, Attribute>
@@ -131,8 +133,14 @@
               , mpl::false_> >
     {};
 
+    namespace detail
+    {
+        BOOST_MPL_HAS_XXX_TRAIT_DEF(types)
+    }
+
     template <typename Expected, typename Variant>
-    struct compute_compatible_component_variant<Expected, Variant, mpl::false_>
+    struct compute_compatible_component_variant<Expected, Variant, mpl::false_
+      , typename enable_if<detail::has_types<Variant> >::type>
     {
         typedef typename traits::variant_type<Variant>::type variant_type;
         typedef typename variant_type::types types;