Boost logo

Boost Users :

From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2006-11-15 07:00:06


Hughes, James wrote:
> Hello all,
>
> I've been trying to create an initiliser for the following (paraphrased)
>
> struct data
> {
> Char *str;

const char*?

> Vector<int> stuff;
> };
>
>
> map<int, struct data> mapstuff = map_list_of
> (1, ("hello", list_of (3) (4) (2)),
> (3, ("goodbye", list_of (1) (3) );
>
> Etc etc
>
> However, this doesn't work, with a very complex compile error from
> assign. I've tried also...
>
> map<int, struct data> mapstuff = map_list_of
> (1, {"hello", list_of (3) (4) (2) } ), // note curly braces
> (3, {"goodbye", list_of (1) (3) ) } );
>
> But that doesn't work either.
>
> Is it actually possible to do something like this, and if so, how?

I suspect that you have to provide a constructor for your data class:

template< class Range >
data( const char* str, const Range& r )
: str(str), stuff(boost::begin(r),boost::end(r))
{ }

-Thorsten


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net