代码之家  ›  专栏  ›  技术社区  ›  21koizyd

用集装箱转发参考[已关闭]

  •  0
  • 21koizyd  · 技术社区  · 9 年前

    有可能 std::vector<T> e、 g是否通过转发引用功能? 我知道

    template<typename T>
    void f(const std::vector<T>&&){} // is rvalue
    template<typename T>
    void f(const std::vector<T>&){} // is lvalue
    

    但我如何为左值和右值生成函数(使用std::vector作为参数)?

    1 回复  |  直到 9 年前
        1
  •  1
  •   Jarod42    9 年前

    我想你想要

    // 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