Boost logo

Boost Users :

Subject: Re: [Boost-users] returning pointer to Boost::assign::map_list_of
From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2010-07-16 08:02:47


alapex0310_at_[hidden] skrev:
> Hi,
>
> I am new to Boost::Assign.
>
> I have a std::map<std::string, unsigned char> and I have a SomeClass
> with constructor SomeClass(std::string, std::map<std::string, unsigned
> char>*) and I want to pass the pointer to the result of map_list_of to
> SomeClass like this:
>
> SomeClass *psc = new
> SomeClass("SomeClassName",map_list_of("one",1)("two",2)("three",3)("four",4)("five",5);
>
>
> In the example at
> http://www.boost.org/doc/libs/1_43_0/libs/assign/doc/index.html#intro ,
> the map_list_of is definitely returning a small map. I don't want to
> pass the map object itself but the pointer to the map object returned by
> map_list_of.

map_list_of returns an unspecified type that converts to a map. So you
have two options:

1. change your argument to map<string,unsigned char>
2. make your constructor a template, and let the "map" argument be
   const T& mapValues instead (I'm assuming you are going to initialize
a map in the constructor.

2) might be more efficient, if that matters

-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