I want to have a forwarding reference which only binds to one type. I can use a static assert, but I wonder if there is a more elegant (C++14/17) way to do this.
Here an example:
#include <iostream>
#include <string>
#include <type_traits>
template<class T>
void f(T&& x) {
// Is there a more elegant way to check for the type than the static_assert?
static_assert(std::is_same<std::string, typename std::remove_cv_t<std::remove_reference_t<T>>>::value);
x = x + "Bar";
std::cout << x << std::endl;
}
int main()
{
std::string name("Foo");
f(name);
f(std::move(name));
}