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 do not know the return value, and even if I put the int there and later copied the type from the error message, its really long type ...
Is there a way to specify the return type as the only return type in the function? is there any workaround unrelated to the huge type in the return type?

+6
source share
2 answers

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

Move typedefs out of function. You can then use it to declare a return type.

If Raymond sends the answer, it should be accepted in my preference - I will send this so that the bit-mass response is not the only one, since I think this medicine is worse than the disease.

+2
source

How about this if you do not want your typedef be removed.

 auto getIt = [] (obj& o, bool getEnd) { return boost::transform_iterator< decltype(boost::bind(transofrmToSomething, _1, o)), decltype(baseIterator(o).first) >( getEnd ? baseIterator(o).second : baseIterator(o).first, boost::bind(transofrmToSomething, _1, o) ); } auto iterateSomething = [] (obj & o) { return std::make_pair(getIt(o,false), getIt(o,true)); } 
0
source

Source: https://habr.com/ru/post/911561/


All Articles