Boost logo

Boost :

From: Paul Hamilton (paul_at_[hidden])
Date: 2003-08-21 20:44:36

I wrote "insert" based on "append" so that you could insert the results
of a parse into a set. It works great!

I based it on "append" in "actions.hpp".

here it is (for inclusion into boost):

     Spirit v1.6.0
     Copyright (c) 1998-2003 Joel de Guzman

     Permission to copy, use, modify, sell and distribute this software
     granted provided this copyright notice appears in all copies. This
     software is provided "as is" without express or implied warranty,
     with no claim as to its suitability for any purpose.

#include "boost/spirit/core/composite/actions.hpp"

namespace boost { namespace spirit {

     // insert_actor class
     // insert_actor is a predefined semantic action functor. It
can be
     // used to extract the result of a successful parse and
inserting it to
     // a variable. The functor overloads two function call
     // operator(), one that takes in a single value argument and
     // that accepts two iterators (first and last).
     // The constructor expects a reference to a variable. The
functor is
     // polymorphic and should work with any variable type as long
as it
     // is compatible with the requirements outlined below.
     // 1 The variable is assumed to be a container of some
sort. An
     // STL container is a perfectly valid candidate.
     // 2 The single argument function call operator inserts the
     // extracted parser result and inserts it to the
     // The container is required to accept the statement:
     // c.insert(value)
     // where c is the container and value is the extracted
     // of the parser.
     // 2.a The container is required to have a member
     // end() that returns an iterator to its 'end'
     // 2.b The container is required to have a member
     // insert that takes in the 'end' iterator and a
     // compatible with the container's element type.
     // 3 The function call operator that takes in the
     // iterator first constructs a value from the iterator
     // before inserting the value to the container. The
     // is required to accept the statement:
     // c.insert(T::value_type(first, last));
     // where c is the container and T is the container type.
     // addition to the requirements 1 and 2 above,
     // 3.a The container is also required to have a typedef
     // value_type (the container's value type) that can
     // constructed given a first/last iterator pair.
     // Requirement 2 is exclusive of requirement 3.
Requirement 3
     // only applies if the corresponding double argument
     // is actually called.
     // Instances of insert_actor are not created directly. Instead
     // generator function:
     // insert(T& ref)
     // taking in a reference to a variable of arbitrary type is
used to
     // instantiate an insert_actor object of the proper type.
        template <typename T>
        class insert_actor
                insert_actor(T& ref_)
                : ref(ref_) {}
                template <typename T2>
                void operator()(T2 const& val) const
                { ref.insert(val); }
                template <typename IteratorT>
                void operator()(IteratorT const& first, IteratorT const& last) const
                        typedef typename T::value_type value_type;
                        ref.insert(value_type(first, last));
                T& ref;

        template <typename T>
        inline insert_actor<T> const
        insert(T& ref)
                return insert_actor<T>(ref);

}} // namespace boost::spirit


Paul Hamilton
pHamtec P/L - Software Makers

The information transmitted is intended only for the person or entity
to which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited. If you
received this in error, please contact the sender and delete the
material from any computer.

Boost list run by bdawes at, gregod at, cpdaniel at, john at