This is where Concepts will shine
#include <string>
#include <iostream>
#include <experimental/type_traits>
namespace xp = std::experimental;
template<typename... Args>
concept bool StringArgs = xp::is_constructible_v<std::string, Args...>;
void internal_func(const std::string& s)
{
std::cout << s << '\n';
}
StringArgs{...T}
void do_with_string(T&&... t)
{
internal_func({std::forward<T>(t)...});
}
int main()
{
do_with_string("foobar", 3U);
do_with_string(std::string("bar"));
do_with_string(3.1);
}
Output:
test.cpp: In function 'int main()':
test.cpp:25:21: error: cannot call function 'void do_with_string(T&& ...) [with T = {double}]'
do_with_string(3.1);
^
test.cpp:16:6: note: constraints not satisfied
void do_with_string(T&&... t)
^~~~~~~~~~~~~~
test.cpp:16:6: note: concept 'StringArgs<double>' was not satisfied
Live example),filterAsm:(commentOnly:!t,directives:!t,labels:!t),version:3).