Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2003-01-23 14:10:25


These are a couple of miscellaneous thoughts as well:

John Spicer wrote:
>I'm happy to voice an opinion, although I don't think I
>have anything to add that hasn't already been said.
>
>I think that is_convertible should be based as closely
>as possible on the definition in clause 4 of the
>standard. As has been pointed out, a problem with this
>is that the standard refers to a source expression, not
>a source type. I think this means that the definition
>of is_converible needs to say something like "True if
>an lvalue of type From can be converted to type To
>according to 4p3" (or make it an rvalue, but you have
>to pick one).

- I understand that this is an informal description on John's part,
just to give us an idea, so I'm not nitpicking on the specific
wording. But it's IMHO important to consider that C++ has at least two
cases of conversions whose validity depends not on the type but on the
specific expression used (off the top of my head they are the only two
ones, but I would be cautious before stating that):

   One is conversion to a pointer type: in this case you can have
   a source expression of any integer type, but it must be constant
   and have the value zero. Example:

       int * p = '\0';

       enum { e = 5 };
       int (*pf)() = 4 % ( e - '\001');

   If you use the indeterminate article "a"/"an" in the wording above
   ("an" rvalue of type From) does it mean: "all" expressions of type
   From or "at least one" expression of type From? Of course, to
   exclude int->pointer-to-object convertibility one would say "all"
   expressions, but I'm not sure whether this is ok for UDTs.

   The other case is the deprecated conversion const char [N] -> char*
   which is valid only if the source expression is a string literal.

- Another point that I would like to understand is "where"
convertibility is checked. Currently convertibility is checked in the
scope of is_convertible<> but is this the intent? This makes a
difference when you have e.g. a private conversion operator:

  class X {
      operator int(); // private
      friend class Y;
  };

  class Y {
      void f() {
          is_convertible<X, int>::value; // true or false??
                                          // or error?
      }
  };

Genny.


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