Error with variadiac template: “parameter pack must be expanded”

后端 未结 1 842
深忆病人
深忆病人 2021-02-18 16:08

Here\'s a variadic template function that I\'ve written:

template
Value& insert(Container& c, Args&         


        
相关标签:
1条回答
  • 2021-02-18 16:40

    The error is due to the missing ellipsis (...) after args when passing all individual parameters (rather than the parameter pack) to emplace_back.

    The fixed (and improved) version:

    template<class Container, class... Args>
    auto insert(Container& c, Args&&... args) -> decltype (c.back()) {
        c.emplace_back(std::forward<Args>(args)...);
        return c.back();
    }
    
    0 讨论(0)
提交回复
热议问题