| Home | Libraries | People | FAQ | More

#### Re-Initialize an Attribute Value before Parsing (Qi)

###### clear_value

The template `clear_value` is a type used as an attribute customization point. It is invoked by the Qi repetitive parsers (Kleene, Plus, List, and Repeat) in order to re-initialize the attribute instance passed to the embedded parser after it has been stored in the provided container. This re-initialized attribute instance is reused during the next iteration of the repetitive parser.

###### Module Headers

    #include <boost/spirit/home/support/attributes.hpp>

Also, see Include Structure.

| Note
This header file does not need to be included directly by any user program as it is normally included by other Spirit header files relying on its content.

###### Namespace

Name
`boost::spirit::traits`

###### Synopsis

    template <typename Attrib, typename Enable>
    struct clear_value
    {
        static void call(Attrib& val);
    };

###### Template parameters

Parameter | Description | Default
--- | --- | ---
`Attrib` | The type, `Attrib` of the attribute to be re-initialized. | none
`Enable` | Helper template parameter usable to selectively enable or disable certain specializations of `clear_value` utilizing SFINAE (i.e. `boost::enable_if` or `boost::disable_if`). | `void`

Notation

`Attrib`

  A type to be used as a container to store attribute values in.

`attr`

  An attribute instance of type `Attrib`.

`T1`, `T2`, ...

  Arbitrary types

###### Expression Semantics

Expression | Semantics
--- | ---

    clear_value<Attrib>::call(Attrib& attr)

Re-initialize the instance referred to by `attr` in the most efficient way.

###### Predefined Specializations

Spirit predefines specializations of this customization point for several types. The following table lists those types together with the types exposed and the corresponding semantics:

Template Parameters | Semantics
--- | ---
`Attrib` | Re-initialize using assignment of default constructed value.
Any type `T` for which `is_container<>::type` is `mpl::true_` | Call the member function `attr.clear()` for the passed attribute instance.
`boost::optional<Attrib>` | Clear the `optional` instance and leave it uninitialized.
`boost::variant<T1, T2, ...>` | Invoke the `clear_value` customization point for the currently held value.
`fusion::tuple<T1, T2, ...>` | Invoke the `clear_value` customization point for all elements of the tuple.
`unused_type` | Do nothing.

###### When to Implement

The customization point `clear_value` needs to be implemented for a specific type whenever this type is to be used as an attribute to be stored into a STL container and if the type cannot be re-initialized using one of the specializations listed above. Examples for this might be types not being default constructible or container types not exposing a member function `clear()`.