Consider:
template <typename InputIt, typename T = typename std::remove_const<typename InputIt::value_type>::type>
std::vector<T> WorkOnIt( InputIt first, InputIt last)
{
std::vector<T> result(first, last);
...fiddle with result...
return result;
}
...
std::set<OneType> goods;
std::vector<OneType> cooked;
...
cooked = WorkOnIt( goods.begin(), goods.end());
This compiles and works but I'm not happy with it even though the call site is clean. If I want to explicitly specify T, I can't just WorkOnIt<CookedType> because I'd have to specify InputIt in front of that. That's ugly since that type is manifest in the argument list. And besides I just want the input iterators to cough up something that is convertible to T. Say like this:
std::set<SourceType> goods;
std::vector<CookedType> cooked;
...
cooked = WorkOnIt<CookedType>( goods.begin(), goods.end());
There must be some enable_if incantation that does what I want but I can't figure it out. (BTW, I'm stuck on C++17.)
You can try using two overloads: one with deduced
Itemparameter and another with explicit.online compiler
If forward declaration of this function is not required then code can be simplified to utilize deduced return type and to eliminate deduced
Itemparameter completely:online compiler