Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return type really long expression

I have the following function:

inline auto iterateSomething(obj & o)
{
    auto iterators = baseIterator(o);
    auto tranformer = boost::bind(transofrmToSomething, _1, o);
    typedef boost::transform_iterator<decltype(tranformer), decltype(iterators.first)> iterator_t;
    iterator_t begin(iterators.first, tranformer);
    iterator_t end(iterators.second, tranformer);
    return std::make_pair(begin, end);
}

As you can see I don't know the return value and even if I put int there and later copy the type from the error message, its a really long type...
Is there a way to specify the return type as the type of the only return in the function? is there any workaround not involving a huge type in the return type?

like image 381
Dani Avatar asked Mar 24 '12 11:03

Dani


1 Answers

I think you should do what Raymond Chen suggested in a comment:

Move the typedefs outside the function. Then you can use it to declare the return type.

If Raymond posts an answer it should be accepted in preference to mine--I'm posting this so that bitmask's answer is not the only one, since I think it is a cure worse than the disease.

like image 50
John Zwinck Avatar answered Oct 20 '22 02:10

John Zwinck