Below is a minimal code which compiles in g++, but gives error in MSVC:
template<typename Type,
typename Return, // <--- error: this is not deduced
typename Container,
typename Parameter>
Container
StringTo (Type&& copy,
const char tokens[],
Return (Container::*Insert) (const Parameter&))
{
static_assert(not std::is_lvalue_reference<Type>::value, "Must be rvalue.");
Container container;
return container;
}
template<typename Type>
auto
StringToVector (Type&& copy,
const char tokens[])
{
static_assert(not std::is_lvalue_reference<Type>::value, "Must be rvalue.");
return StringTo(std::move(copy), tokens, &std::vector<Type>::push_back); // <--- here
}
int main()
{
auto v = StringToVector(std::string("hello world"), " ");
}
As per this post, it's a bug in MSVC which is not yet fixed: Visual Studio 2017 - could not deduce template argument (with variadic templates)
Question: What is the workaround to fix it for this specific case?
Update: This bug isn't fixable, & I am open to changing of design/interface. You are welcome to post it as an answer. Will accept the best one.