[mpl][fusion] How to transform vector_c into std::vector?

How does one transform an mpl:vector_c into a regular std::vector?
Sample input:
typedef mpl::vector

On Wed, 27 Nov 2013 21:09:04 -0800, TONGARI J
2013/11/28 Mostafa
How does one transform an mpl:vector_c into a regular std::vector?
Sample input:
typedef mpl::vector
, int_<11>, int_<12> > some_vector_c; Perhaps:
std::vector<int> v; fusion::for_each(some_vector_c(), [&v](int val){v.push_back(val);});
Thanks, I ended up using mpl's for_each. Even though I don't quite understand how it works. Specifically, what does boost::get do? I couldn't find any documentation on it.

On 11/28/13 00:37, Mostafa wrote:
On Wed, 27 Nov 2013 21:09:04 -0800, TONGARI J
wrote: 2013/11/28 Mostafa
How does one transform an mpl:vector_c into a regular std::vector?
Sample input:
typedef mpl::vector
, int_<11>, int_<12> > some_vector_c; Perhaps:
std::vector<int> v; fusion::for_each(some_vector_c(), [&v](int val){v.push_back(val);});
Thanks, I ended up using mpl's for_each. Even though I don't quite understand how it works. Specifically, what does boost::get do? I couldn't find any documentation on it.
I assume you mentioned boost::get because it appears in the for_each documentation here: http://www.boost.org/doc/libs/1_55_0/libs/mpl/doc/refmanual/for-each.html specifically in this quote: --{--cut here-- Postcondition: Equivalent to typedef begin<Sequence>::type i1; value_initialized< deref<i1>::type > x1; f(boost::get(x1)); typedef next<i1>::type i2; value_initialized< deref<i2>::type > x2; f(boost::get(x2)); ... value_initialized< deref<in>::type > xn; f(boost::get(xn)); typedef next<in>::type last; where n == size<s>::value and last is identical to end<s>::type; no effect if empty<s>::value == true. --}--cut here-- And now I see why you asked your question because boost::get(x1) seems to be redundant. AFAICT, just passing th x1 or x2 ... or xn would work. Hence, like Mostafa, I'd like some clarification of why boost::get is necessary in the mpl::for_each documentation. Googling boost::get leads to: http://www.boost.org/doc/libs/1_35_0/doc/html/boost/get_id405862.html which indicates the argument to boost::get is a boost::variant, which doesn't clarify anything for me. -regards, Larry

On 11/28/13 00:37, Mostafa wrote:
On Wed, 27 Nov 2013 21:09:04 -0800, TONGARI J
wrote: 2013/11/28 Mostafa
How does one transform an mpl:vector_c into a regular std::vector?
Sample input:
typedef mpl::vector
, int_<11>, int_<12> > some_vector_c; Perhaps:
std::vector<int> v; fusion::for_each(some_vector_c(), [&v](int val){v.push_back(val);});
Thanks, I ended up using mpl's for_each. Even though I don't quite understand how it works. Specifically, what does boost::get do? I couldn't find any documentation on it. See it's definition here:
http://www.boost.org/doc/libs/1_55_0/libs/utility/value_init.htm The mpl for_each doc would be clearer if: typedef begin<Sequence>::type i1; value_initialized< deref<i1>::type > x1; f(boost::get(x1)); were replaced with: typedef begin<Sequence>::type i1; value_initialized< deref<i1>::type > x1; f(x1.data()); then there would be no chance about which get was being used. -Larry

On Thu, 28 Nov 2013 11:21:42 -0800, Larry Evans
On 11/28/13 00:37, Mostafa wrote:
On Wed, 27 Nov 2013 21:09:04 -0800, TONGARI J
wrote: 2013/11/28 Mostafa
How does one transform an mpl:vector_c into a regular std::vector?
Sample input:
typedef mpl::vector
, int_<11>, int_<12> > some_vector_c; Perhaps:
std::vector<int> v; fusion::for_each(some_vector_c(), [&v](int val){v.push_back(val);});
Thanks, I ended up using mpl's for_each. Even though I don't quite understand how it works. Specifically, what does boost::get do? I couldn't find any documentation on it. See it's definition here:
http://www.boost.org/doc/libs/1_55_0/libs/utility/value_init.htm
The mpl for_each doc would be clearer if:
typedef begin<Sequence>::type i1; value_initialized< deref<i1>::type > x1; f(boost::get(x1));
were replaced with:
typedef begin<Sequence>::type i1; value_initialized< deref<i1>::type > x1; f(x1.data());
then there would be no chance about which get was being used.
-Larry
Thanks. It seems get is used because it's recommended practice. See the section "Recommended practice: The non-member get() idiom". It would have been quite helpful if the mpl doc linked to this section of the value_init doc. Mostafa
participants (3)
-
Larry Evans
-
Mostafa
-
TONGARI J