How can I use boost :: adapters :: transform to create a range from a templated class and a vector?
I asked a question about using a lambda to achieve something like this earlier, but couldn't get it to work , so I tried to approach the problem using a functor instead. This is probably all the same in the sense that it is not related to object construction std::function
and is closer to the example case given in the documentation .
Here's a simple setup that illustrates my problem:
#include <boost/range/adaptor/transformed.hpp>
#include <vector>
// some structure
template <typename T>
struct MyStruct
{
MyStruct(T t)
{
}
};
template <typename T>
struct Converter
{
using return_type = MyStruct<T>;
return_type operator()(const T& value)
{
return return_type(value);
}
};
int main(int argc, const char* argv[])
{
std::vector<int> vec {1, 2, 3};
auto val = vec | boost::adaptors::transformed(Converter<int>());
return 0;
}
When I try to compile this, I get the following error:
/home/user/packages/boost/mpl/eval_if.hpp:38:31: error: no type name specified 'Type in'
boost::mpl::eval_if<boost::is_same<boost::use_default, boost::use_default>, boost::result_of<const Converter<int>(int&)>, boost::mpl::identity<boost::use_default> >::f_ {aka struct boost::result_of<const Converter<int>(int&)>}
I'm not sure what to do about it. I don't see any errors in the code. Any ideas?
source to share
The error tells you it boost::result_of<const Converter<int>(int&)>
has no member type
. In other words, the function call operator does not work if an object is used const Converter<int>
. Once you know the problem, it's easy to figure out what's wrong:
return_type operator()(const T& value) const
// ^^^^^
{
return return_type(value);
}
source to share