Boost logo

Boost :

Subject: Re: [boost] Query of interest for a container output library
From: Tal Zion (talzion12_at_[hidden])
Date: 2013-01-30 10:27:22


The library defines a templated operator<< that is enabled (by
Boost.EnableIf) for all types that have a const_iterator typedef, or
evaluate to true in boost::fusion::is_sequence<T> and are not already
ostreamable.

boost::iterator_range already defines operator<< and so the library will
"back down" and let iterator_range do its job. The library tries not to
interfere with other objects. If another object says it can be outputted to
an ostream, the library "believes" it.
By using this philosophy, the library prevents any ambiguity in operator<<.

But to answer your question, the library is completely generic and it does
support arbitrary ranges.

Here are some code snippets that show how the library captures a range:

template <typename T>
struct is_ostreamable : has_left_shift<std::ostream&amp;, T const&amp;> {};

struct sequence {
    BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_const_iterator, const_iterator,
false)

    /**
     * Determines if a type is a sequence.
     */
    template <typename I, typename T=typename remove_reference<I>::type >
    struct is : mpl::or_<
        has_const_iterator<T>,
        fusion::traits::is_sequence<T>
> {};
};

/**** IN GLOBAL NAMESPACE ****/
template <typename T>
typename boost::enable_if<
    boost::mpl::and_<
        boost::stringize::detail::sequence::is<T>,
        boost::mpl::not_< // ignore everything that is ostreamable already
            boost::stringize::detail::is_ostreamable<T>
>
>,
    std::ostream&
>::type
operator<< (std::ostream& out, T const& t) {
    return boost::stringize::detail::print(out, t);
}

This code may change in the future to check if T::value_type is also
ostreamable.

--
View this message in context: http://boost.2283326.n4.nabble.com/Query-of-interest-for-a-container-output-library-tp4641997p4642003.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk