Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56664 - in branches/release: boost/spirit/home/karma/operator libs/spirit/test/karma
From: hartmut.kaiser_at_[hidden]
Date: 2009-10-08 20:53:22


Author: hkaiser
Date: 2009-10-08 20:53:21 EDT (Thu, 08 Oct 2009)
New Revision: 56664
URL: http://svn.boost.org/trac/boost/changeset/56664

Log:
Spirit: merged latest sequence fix to release branch
Text files modified:
   branches/release/boost/spirit/home/karma/operator/sequence.hpp | 21 +++++++++++++++------
   branches/release/libs/spirit/test/karma/sequence.cpp | 18 ++++++++++++++++++
   2 files changed, 33 insertions(+), 6 deletions(-)

Modified: branches/release/boost/spirit/home/karma/operator/sequence.hpp
==============================================================================
--- branches/release/boost/spirit/home/karma/operator/sequence.hpp (original)
+++ branches/release/boost/spirit/home/karma/operator/sequence.hpp 2009-10-08 20:53:21 EDT (Thu, 08 Oct 2009)
@@ -121,9 +121,9 @@
         // standard case. Attribute is a fusion tuple
         template <
             typename OutputIterator, typename Context, typename Delimiter
- , typename Attribute>
+ , typename Attribute, typename Pred1, typename Pred2>
         bool generate_impl(OutputIterator& sink, Context& ctx
- , Delimiter const& d, Attribute& attr_, mpl::false_) const
+ , Delimiter const& d, Attribute& attr_, Pred1, Pred2) const
         {
             typedef detail::fail_function<
                 OutputIterator, Context, Delimiter> fail_function;
@@ -141,12 +141,14 @@
               , predicate());
         }
 
- // Special case when Attribute is an stl container
+ // Special case when Attribute is an stl container and the sequence's
+ // attribute is not a one element sequence
         template <
             typename OutputIterator, typename Context, typename Delimiter
           , typename Attribute>
         bool generate_impl(OutputIterator& sink, Context& ctx
- , Delimiter const& d, Attribute const& attr_, mpl::true_) const
+ , Delimiter const& d, Attribute const& attr_
+ , mpl::true_, mpl::false_) const
         {
             // return false if *any* of the generators fail
             typedef detail::fail_function<
@@ -164,8 +166,15 @@
         bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
           , Attribute const& attr) const
         {
- return generate_impl(sink, ctx, d, attr
- , traits::is_container<Attribute>());
+ typedef typename traits::is_container<Attribute>::type
+ is_container;
+
+ typedef typename attribute<Context>::type_ attr_type_;
+ typedef typename traits::one_element_sequence<attr_type_>::type
+ is_one_element_sequence;
+
+ return generate_impl(sink, ctx, d, attr, is_container()
+ , is_one_element_sequence());
         }
 
         template <typename Context>

Modified: branches/release/libs/spirit/test/karma/sequence.cpp
==============================================================================
--- branches/release/libs/spirit/test/karma/sequence.cpp (original)
+++ branches/release/libs/spirit/test/karma/sequence.cpp 2009-10-08 20:53:21 EDT (Thu, 08 Oct 2009)
@@ -145,6 +145,24 @@
         }
     }
 
+ // test special case where sequence has a one element vector attribute
+ // sequence and this element is a rule (attribute has to be passed through
+ // without change)
+ {
+ typedef spirit_test::output_iterator<char>::type outiter_type;
+ namespace karma = boost::spirit::karma;
+
+ karma::rule<outiter_type, std::vector<int>()> r = -(int_ % ',');
+ std::vector<int> v;
+ BOOST_TEST(test(">", '>' << r, v));
+
+ v.push_back(1);
+ v.push_back(2);
+ v.push_back(3);
+ v.push_back(4);
+ BOOST_TEST(test(">1,2,3,4", '>' << r, v));
+ }
+
     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