variadic templates - ambiguous call

后端 未结 2 1648
有刺的猬
有刺的猬 2021-01-04 14:15

The following code compiles in both gcc 4.7.2 and MSVC-11.0:

template 
void foo(T bar) {}

template 
vo         


        
2条回答
  •  太阳男子
    2021-01-04 14:43

    This is considered a defect in the current standard. Even the standard itself relies on non-variadic templates to be partially ordered before variadic ones in the specification of std::common_type:

    §20.9.7.6 [meta.trans.other] p3

    The nested typedef common_type::type shall be defined as follows:

    template  struct common_type;
    
    template 
    struct common_type {
      typedef T type;
    };
    
    template 
    struct common_type {
      typedef decltype(true ? declval() : declval()) type;
    };
    
    template 
    struct common_type {
      typedef typename common_type::type, V...>::type type;
    };
    

    Specifically common_type vs common_type.

提交回复
热议问题