Boost logo

Boost Users :

Subject: Re: [Boost-users] [fusion] transform a heterogeneous vector
From: Jean-Louis Leroy (jl_at_[hidden])
Date: 2009-09-20 17:05:05


Christopher Schmidt wrote:
> Fusion uses boost::result_of to determine the return type of a call
> expression. Therefore you just need to define a result-metafunction.
Thanks. It works. However two things bother me.

First there's the warning :

    1>c:\program
    files\boost\boost_1_39\boost\fusion\view\transform_view\detail\deref_impl.hpp(42)
    : warning C4172: returning address of local variable or temporary
    1> c:\program
    files\boost\boost_1_39\boost\fusion\view\transform_view\detail\deref_impl.hpp(41)
    : while compiling class template member function 'const int
    &boost::fusion::extension::deref_impl<boost::fusion::transform_view_iterator_tag>::apply<Iterator>::call(const
    Iterator &)'
    1> with
    1> [
    1>
    Iterator=boost::fusion::transform_view_iterator<boost::fusion::vector_iterator<const
    boost::fusion::vector<int,int,double,boost::fusion::void_,boost::fusion::void_,boost::fusion::void_,boost::fusion::void_,boost::fusion::void_,boost::fusion::void_,boost::fusion::void_>,0>,triple2>
    1> ]
    1> c:\program
    files\boost\boost_1_39\boost\fusion\iterator\deref.hpp(53) : see
    reference to class template instantiation
    'boost::fusion::extension::deref_impl<boost::fusion::transform_view_iterator_tag>::apply<Iterator>'
    being compiled
    1> with
    1> [
    1>
    Iterator=boost::fusion::transform_view_iterator<boost::fusion::vector_iterator<const
    boost::fusion::vector<int,int,double,boost::fusion::void_,boost::fusion::void_,boost::fusion::void_,boost::fusion::void_,boost::fusion::void_,boost::fusion::void_,boost::fusion::void_>,0>,triple2>
    1> ]
    etc etc etc

Also, I see that transform returns a view. I need a proper vector that
is distinct from the input vector. Here's a bit of context. I am
building a recipient for one row in a database query. I have a vector
of Exprs, one for each column in the select. Expr has a type member. I
want to make a vector with an element for each Expr, initialized to the
type's default value (as per type()).

I.e. something like this :

    struct f { /* ... */ template<typename Expr> operator ()(Expr) {
return typename Expr::type(); }
    typedef result_of::transform<SelectList, f>::type row_type;
    row_type row;
    transform(select.exprs, row); // type of select.exprs is SelectList
    std::deque<row_type> results;
    while (data) {
       for_each(row, read_fun(...));
       results.push_back(row);
    }

Alas row_type is going to be a view :-/

J-L

J-L


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