Why is this ambiguity here?

前端 未结 6 1168
南笙
南笙 2020-12-02 20:35

Consider I have the following minimal code:

#include 

template
struct TData
{
    typedef typename boost:         


        
6条回答
  •  悲哀的现实
    2020-12-02 20:46

    Overload resolution is a headache. But since you stumbled on a fix (eliminate conversion of the index operand to operator[]) which is too specific to the example (literals are type int but most variables you'll be using aren't), maybe you can generalize it:

    template< typename IT>
    typename boost::enable_if< typename boost::is_integral< IT >::type, value_type & >::type
    operator [] ( IT id ) { return data[id]; }
    

    Unfortunately I can't test this because GCC 4.2.1 and 4.5 accept your example without complaint under --pedantic. Which really raises the question whether it's a compiler bug or not.

    Also, once I eliminated the Boost dependency, it passed Comeau.

提交回复
热议问题