Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2007-08-21 05:15:40


Edson Tadeu wrote:
> Please take a look at the following small test code:

> When I try to use is_convertible<T, int>::value, with T being a
> boost::assign::list_of, it wrongly results in a "true" value. This
> code compiles on MSVC 8.0, and running it gives the following output:
>
> 1, 0, 1, 2
>
> If you uncomment line 22 (i.e., if you *really* try to convert the
> types), the code will not compile, with an error on line 19:

As far as is_convertible is concerned this behaviour is unavoidable -
assign::list_of *does* contain a suitable member conversion operator,
declared as:

template< class T >
class generic_list
{
  // details snipped...
  template< class Container >
  operator Container() const;
}

The implementation of is_convertible only determines that the declaration
exists, it doesn't check that the code contained within the conversion
operator actually compiles, and indeed there is no way it can do so.

We have asked compiler vendors in the past for a generic
__does_this_code_compile(code) operator, but they tend to shudder and run
screaming from the room when this is suggested :-(

John.


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