Boost logo

Boost Users :

Subject: [Boost-users] [mpl][type_traits] Transforming to common type
From: Bjorn Reese (breese_at_[hidden])
Date: 2014-02-22 08:25:50


Given a type T, I am trying to transform a type list into another
containing the common type between T and the individual types in the
type list.

When I compile the example below, I get the following error:

/usr/local/include/boost/type_traits/common_type.hpp:111:42: error:
incompatible operand types ('mpl_::arg<1>' and 'int')
   typedef decltype(declval<bool>() ? declval<T>() : declval<U>()) type;
                                    ^ ~~~~~~~~~~~~ ~~~~~~~~~~~~

It appears that the placeholder is not expanded to its actual type.

If I use, say, decay<> instead of common_type<>, the example works just
fine.

Does anybody know how I can make it work?

Example code:

#include <boost/mpl/vector.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/type_traits/common_type.hpp>

int main()
{
     typedef boost::mpl::vector<int, double> sequence_types;
     typedef boost::mpl::transform<
         sequence_types,
         // This is causing the problem
         boost::common_type<boost::mpl::_1, int>::type
>::type transformed_types;

     return 0;
}


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