make_unique and perfect forwarding

后端 未结 6 1732
南方客
南方客 2020-11-22 10:24

Why is there no std::make_unique function template in the standard C++11 library? I find

std::unique_ptr p(new SomeUs         


        
6条回答
  •  难免孤独
    2020-11-22 11:02

    In C++11 ... is used (in template code) for "pack expansion" too.

    The requirement is that you use it as a suffix of an expression containing an unexpanded pack of parameters, and it will simply apply the expression to each of the elements of the pack.

    For example, building on your example:

    std::forward(args)... -> std::forward(1), std::forward(2),
                                                         std::forward(3)
    
    std::forward(args...) -> std::forward(1,2,3)
    

    The latter being incorrect I think.

    Also, pack of arguments may not be passed to a function unexpanded. I am unsure about a pack of template parameters.

提交回复
热议问题