template<typename T>
struct test
{
std::string key;
T value;
template<typename U>
using decay = typename std::decay<U>::type;
template<typename U = decay<T>, typename US = decay<std::string>>
test(U&& _value, US&& _key) : value(std::forward<U>(_value)), key(std::forward<US>(_key)){}
};
我在几乎每个项目中都使用衰减。我想问一下,这样做是否是一个好的选择,而不是像这样编写代码:
test(T&& _value, std::string&& _key) : value(std::move(_value)), key(std::move(_key)){}
test(const T& _value, std::string&& _key) : value(_value), key(std::move(_key)){}
test(T&& _value, const std::string& _key) : value(std::move(_value)), key(_key){}
test(const T& _value, const std::string& _key) : value(_value), key(_key){}
decay
吗? - super