4

考虑这种可变参数模板疯狂从一种类型转换的阵列到另一:Variadic模板元编程:铿锵++或g ++中的错误?

#include <array> 
#include <type_traits> 

template <typename Type> 
class Converter 
{ 
    public: 
     template <typename OtherType, unsigned int OtherSize, class Array, typename... Types, class = typename std::enable_if<sizeof...(Types) != OtherSize>::type> 
     static constexpr const std::array<OtherType, OtherSize> convert(const Array source, const Types&... values); 
     template <typename OtherType, unsigned int OtherSize, class Array, typename... Types, class = typename std::enable_if<sizeof...(Types) == OtherSize>::type> 
     static constexpr const std::array<OtherType, OtherSize> convert(const Array, const Types... values); 
}; 

template <typename Type> 
template <typename OtherType, unsigned int OtherSize, class Array, typename... Types, class> 
constexpr const std::array<OtherType, OtherSize> Converter<Type>::convert(const Array source, const Types&... values) 
{ 
    return convert<OtherType, OtherSize>(source, values..., OtherType(source[sizeof...(values)])); 
} 

template <typename Type> 
template <typename OtherType, unsigned int OtherSize, class Array, typename... Types, class> 
constexpr const std::array<OtherType, OtherSize> Converter<Type>::convert(const Array, const Types... values) 
{ 
    return std::array<OtherType, OtherSize>({{values...}}); 
} 

int main(int argc, char* argv[]) 
{ 
    Converter<double>::convert<int, 3>(std::array<double, 3>({{1., 2., 3.}})); 
    return 0; 
} 

此代码编译以及下克++ 4.7和g ++ 4.8但不低于铛++ 3.2:

main.cpp:16:67: error: conflicting types for 'convert' 
constexpr const std::array<OtherType, OtherSize> Converter<Type>::convert(const Array source, const Types&... values) 
                   ^
main.cpp:9:65: note: previous declaration is here 
     static constexpr const std::array<OtherType, OtherSize> convert(const Array source, const Types&... values); 
                   ^
main.cpp:23:67: error: conflicting types for 'convert' 
constexpr const std::array<OtherType, OtherSize> Converter<Type>::convert(const Array, const Types... values) 
                   ^
main.cpp:11:65: note: previous declaration is here 
     static constexpr const std::array<OtherType, OtherSize> convert(const Array, const Types... values); 

g ++是否过于宽容,或者它是铿锵++的错误(如果是这样,是否有一个公共bugng的bug追踪器)?

回答

4

是啊,这是this bug已经在铛报告并固定。

+0

并且与其他一些主要编译器供应商不同,此类错误修复很快就会在新版本中发布。 – TemplateRex 2013-05-09 21:53:13