> Hey folks, new toy (actually, as_string and as_wstring have been around
> for a week or so).
Bryce, thanks for working on this! That's an excellent move.
> as<T> and friends are qi and karma directives that cause the attribute of
> to be assigned/extracted atomically. Usually in Spirit, a container which
> is an
> attribute (vector<A>) is assigned or extracted through iterative behavior
> Qi, repeated calls to traits::push_back. For Karma, iterators are
> extracted with
> traits::begin and traits::end, and a for loop iterates through them via
> traits::next). as<T> causes the attribute of it's subject to be assigned
> all at
I'm not sure yet whether this is beneficial at all, but at least for strings
it's a nice generalization helping to integrate utree better.
> For qi::as<T>: A temporary object t of type T is supplied as the
> attribute for the subject parser. If the subject parser succeeds, t is
> to the as directive's attribute parameter. The assignment is performed by
> calling traits::assign_to, which dispatches to Spirit assignment CPs.
> For karma::as<T>: A runtime check for dynamic data structures such as
> utree and variant is first performed on the attribute, to ensure that an
> of type T can be extracted from it. This is done by calling
> which dispatches to a new Spirit CP, attribute_as_xxx.
> If the attribute is
> valid, the subject generator is invoked, supplied with a temporary object
> type T. The actual extraction is done by a call to traits::as<T>, which
> dispatches to attribute_as_xxx.
Can we get rid of the _xxx, please? attribute_valid_as<> should be just
fine, I believe. I tend to prefer aligning the naming of the function and
the actual customization point.
Additionally, as already discussed on IRC, I'd suggest to unify
attribute_valid_as<> and the existing has_optional_value<> customization
points. The former is a generalization of the latter, suggesting to get rid
> as_string and as_wstring are parser instances that are equal to:
> typedef qi::as<std::string> as_string_type;
> as_string_type const as_string = as_string_type();
> typedef qi::as<std::wstring> as_wstring_type;
> as_wstring_type const as_wstring = as_wstring_type();
> Because the above definitions would require global ctors, as_string and
> as_wstring are actually static initialized spirit terminals.
> Docs are forthcoming.
I'd insist on that :-P
> Anyone have any ideas for a better name than as<T> for this parser?