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

后端 未结 1 850
深忆病人
深忆病人 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
    auto insert(Container& c, Args&&... args) -> decltype (c.back()) {
        c.emplace_back(std::forward(args)...);
        return c.back();
    }
    

    0 讨论(0)
提交回复
热议问题