[fusion][mpl] transform_view and as_vector compilation error
Hi, we have a problem in our code base. I extracted a minimal example, see below. The code works with g++ version up to 4.8.1 and C++11 but fails to compile with gcc-4.8.1 and clang3.2 and newer. Any ideas what goes wrong here? Should I further dig into the problem? I am using boost 1.54. #include <boost/fusion/include/vector.hpp> #include <boost/fusion/include/as_vector.hpp> #include <boost/fusion/include/transform_view.hpp> struct t1 { struct result_type1 {}; }; struct t2 { struct result_type1 {}; }; struct my_transform { template< class > struct result; template< class F , class T > struct result< F( T ) > { typedef typename T::result_type1 type; }; }; int main( int argc , char *argv[] ) { namespace fusion = boost::fusion; typedef fusion::vector< t1 , t2 > vector_type; typedef fusion::transform_view< vector_type , my_transform > transform_type; typedef fusion::result_of::as_vector< transform_type >::type transformed_vector_type; return 0; }
On 15/12/2013 12:17 p.m., Karsten Ahnert wrote:
Hi,
we have a problem in our code base. I extracted a minimal example, see below. The code works with g++ version up to 4.8.1 and C++11 but fails to compile with gcc-4.8.1 and clang3.2 and newer. Any ideas what goes wrong here? Should I further dig into the problem?
Newer compiler versions that support N3276 decltype do not use the result_of protocol anymore, instead boost::result_of uses decltype directly. For that to work you need an operator(), which was always a requirement for transform_view and other functions expecting a function object.
struct my_transform { template< class > struct result;
template< class F , class T > struct result< F( T ) > { typedef typename T::result_type1 type; };
template <typename T> typename T::result_type1 operator()(T) const;
};
Regards, -- Agustín K-ballo Bergé.- http://talesofcpp.fusionfenix.com
On 12/15/2013 05:24 PM, Agustín K-ballo Bergé wrote:
On 15/12/2013 12:17 p.m., Karsten Ahnert wrote:
Hi,
we have a problem in our code base. I extracted a minimal example, see below. The code works with g++ version up to 4.8.1 and C++11 but fails to compile with gcc-4.8.1 and clang3.2 and newer. Any ideas what goes wrong here? Should I further dig into the problem?
Newer compiler versions that support N3276 decltype do not use the result_of protocol anymore, instead boost::result_of uses decltype directly. For that to work you need an operator(), which was always a requirement for transform_view and other functions expecting a function object.
struct my_transform { template< class > struct result;
template< class F , class T > struct result< F( T ) > { typedef typename T::result_type1 type; };
template <typename T> typename T::result_type1 operator()(T) const;
};
Ok, thank you. It works. I never needed this operator, since I only used the result_of class. I think a MPL transform would have be enough for it to work correctly.
Regards,
participants (2)
-
Agustín K-ballo Bergé
-
Karsten Ahnert