How will Concepts-Lite interact with variadic templates?

前端 未结 2 575
耶瑟儿~
耶瑟儿~ 2021-02-05 23:33

I watched Bjarne Strustrup\'s talk in Going Native 2013 and he gives the following example for the upcoming concepts-lite feature of C++.

void sort(Container&         


        
2条回答
  •  生来不讨喜
    2021-02-05 23:53

    I believe the intention of the terse format is to require all elements in the pack must be of the same type. This is derived from the example in n3701 §5.3, which states that

    void sort(Random_access_iterator p, Random_access_iterator q);
    

    should be equivalent to

    template
    void sort(__Ran p, __Ran q);
    

    because

    "By default, if you use the same constrained parameter type name for two arguments, the types of those arguments must be the same. We chose to make repeated use of a constrained parameter type name imply “same type” because that (in most environments) is the most common case, it would be odd to have an identifier used twice in a scope have two different meanings, and the aim here is to optimize for terse notation of the simplest case."

    But I don't see how it can be expanded into your maximum with the current ('14) template syntax. In proposed change of standard wording in n3701 it only talked about the simple case

    §7.1.6.5 Constrained type specifiers [dcl.spec.constrained]

    ...

    The first use of concept-name or partial-concept-id within a scope binds that name to the placeholder type so that subsequent uses of the same name refer to the same type.

    But it doesn't explain the interaction of variadics. Maybe need to wait for the 3rd revision to clarify this.

提交回复
热议问题