C++ 用集装箱转发参考资料

C++ 用集装箱转发参考资料,c++,c++11,c++14,rvalue,lvalue,C++,C++11,C++14,Rvalue,Lvalue,有可能通过转发引用来提供std::vector功能? 我知道 template<typename T> void f(const std::vector<T>&&){} // is rvalue template<typename T> void f(const std::vector<T>&){} // is lvalue 模板 void f(const std::vector&&{}//是右值 模板 void f(co

有可能通过转发引用来提供
std::vector
功能? 我知道

template<typename T>
void f(const std::vector<T>&&){} // is rvalue
template<typename T>
void f(const std::vector<T>&){} // is lvalue
模板
void f(const std::vector&&{}//是右值
模板
void f(const std::vector&){}//是左值
但是我怎样才能为左值和右值生成函数(使用std::vector作为参数)?

我想你需要

// traits for detecting std::vector
template <typename> struct is_std_vector : std::false_type {};
template <typename T, typename A>
struct is_std_vector<std::vector<T, A>> : std::true_type {};

template<typename T>
std::enable_if_t<is_std_vector<std::decay_t<T>>::value>
f(T&&); // Take any std::vector
//检测std::vector的特征
模板结构是_std_vector:std::false_type{};
模板
结构是_std_vector:std::true_type{};
模板
std::如果启用,则启用
f(T&&);//取任意一个std::vector

我对此有点生疏,但我相信a在函数中的形式:
void f(T&&)
只有在T是“未知”类型(如模板参数)的情况下才会是“通用引用”您是否询问模板函数的参数,如您所示,是否是通用引用?(根据Scott Meyers的定义,我相信谁发明了这个词)请用完整的句子,这样我们就可以知道你在问什么。迈尔斯在他那本实用的现代C++书中创造了这个术语。C++现在称之为转发引用。@ 21Koiydd:每个学期都有人发明了!我考虑过这件事,但我必须确定。谢谢。好的,我实现了这一点,但如果需要,我在函数返回值方面有问题,我尝试了
typename std::enable\u if\u t::type
,但在这种情况下不起作用。课程类型(
T
-input)