Why won't template parameter pack be deduced to multiple type arguments in function call?

前端 未结 2 629
小鲜肉
小鲜肉 2021-02-12 16:29

I have a class templated on a type parameter and parameter pack, and am confused about type-deduction of this type; while writing an output-streaming operator I discovered a par

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-12 16:33

    Wow, I would have thought this was fixed already, but it still doesn't work in prerelease GCC 4.9 and Clang 3.4 builds (courtesy Coliru).

    The workaround is simple: use partial specialization to deduce the template arguments elsewhere.

    template
    struct foo; // unimplemented
    
    template
    struct foo< T, Ts ... > // specialization for at least one argument
    { /* ... */ };
    
    template< class... Ts >
    std::ostream& operator<<( std::ostream& os, const foo& )
    {
      return os << 42;
    }
    

    Why both GCC and Clang can't solve this years-old bug by imitating the workaround in the general case, I don't know. The compiler vendors are perhaps facing an unfortunate choice between performance and correctness.

提交回复
热议问题