Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-08-22 14:45:51


----- Original Message -----
From: "David Abrahams" <dave_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, August 21, 2002 7:58 PM
Subject: Re: [boost] value_initialized<> utility template

> [snipped]
>
> > I initially used a dispatch upon T's const-ness.
> > The const-T case is trivial,
> > but the 'non-const' T suffers from this: both operators cannot be
> provided
> > because they yield ambiguity:
> >
> > operator T const&() const { return x ; }
> > operator T&() { return x ; }
>
> Really? What's the case that produces it? I don't know a workaround for
> that one.
>
With:

struct X
{
  operator int&();
  operator int const&() const ;
} ;

int main()
{
 X a ;
 ( a == 1 ) ;
}

Both BCC5.5.1/5.6 say: (but I don't have BCB6 update #2)
[C++ Error] test.cpp(10): E2015 Ambiguity between 'X::operator int &()' and
'X::operator const int &() const'

GCC2.95.2 says: (I don't have the latest gcc yet)
warning: choosing `X::operator int &()' over `X::operator const int &()
const'
warning: for conversion from `X' to `int'
warning: because conversion sequence for the argument is better

MSVC 6.0 says: (don't have any newer)
error C2593: 'operator ==' is ambiguous

And of course, Comeau Online compiles it fine.

I'd like to know how the latest releases of these (and other compilers)
handle this before I make a decision.

TIA,

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk