Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-10-09 12:37:05


From: "Thorsten Ottosen" <nesotto_at_[hidden]>
>
> I also think the first is best. Regarding the names, wouldn't understand
why
> they couln't
> be as above. The user will include it like this:
>
> #include <init/include>
>
> just like I include everything from boost as
>
> #include <boost/xxxx.hpp>
>
> The namespace kinda reflects the directory structure. Moreover, the new
> headers actually replaces the old ones
> for those who is using it which means it is almost the standard header.
> Comments are welcome :-)

Why do you need so many headers?

template<class C> class initializer
{
public:

    explicit initializer(C & c): c_(c)
    {
    }

    template<class V> initializer & operator()(V const & v)
    {
        c_.insert(c_.end(), v);
        return *this;
    }

    template<class K, class V> initializer & operator()(K const & k, V const
& v)
    {
        typedef typename C::value_type P;
        c_.insert(P(k, v));
        return *this;
    }

private:

    initializer & operator=(initializer const &);
    C & c_;
};

template<class C> initializer<C> init(C & c)
{
    return initializer<C>(c);
}

Usage:

init(container)(value1)(value2)(value3);

or

init(map)(key1, value1)(key2, value2);


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