Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost-users] [assign] std::vector initialisation by boost::assign::list_of
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2010-03-18 04:39:09


Hi Andrey,

you can pass list by value. Compiler should be smart enough to eliminate the
temporary.
On the other hand, if you vector is always constant consider using a fusion
vector.

You can also introduce a helper function, which fills the vector with the
desired list
and returns it:

struct sss
{
   sss()
     : v(vector_items)
   {}

private:
   // this function should be inlined with temporary elimination
   static vector<int> vector_items()
   {
      vector<int> v = list_of...;
      return v;
   }
};

Hope that helps,
Ovanes

On Wed, Mar 17, 2010 at 8:30 PM, Andrey Torba <andreytorba_at_[hidden]> wrote:

> On 17 March 2010 17:58, Ovanes Markarian <om_boost_at_[hidden]> wrote:
> > vector<int> v(my_iterator(list_of(1)(2)), my_iterator());
>
> I think that result of `list_of` will be destroyed after
> `my_iterator(...)` call, so `my_iterator` will not be valid.
>
>
> --
> Regards, Andrey
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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