Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2003-01-19 06:37:40


On Sat, 18 Jan 2003 20:16:36 -0700, Greg Colvin
<Gregory.Colvin_at_[hidden]> wrote:

>At a meeting years ago I proposed to make string literals more
>useful as constant expressions, but we decided against that.
>As I recall part of the problem is that linkers are free to map
>the same literal string to different addresses in different
>compilation units.

Well, it's obvious that implications must be carefully analyzed. What
I was thinking to in the context of this thread was probably something
*less general* than what you proposed: making an expression of the
form

   string-literal [ integral-constant-expression ]
     or
   integral-constant-expression [ string-literal ]

an integral constant expression of type const char. Problems with the
fact that such expression is currently an lvalue are easily solvable
with appropriate rules. The idea was that given, for instance,

  template <char c>
  struct binary_digit {
     static const int value = (c == '0'? 0 : 1);
  };

you would be able to write:

  binary_digit <"110"[1]>::value

just like you can now write

  binary_digit <'1'>::value

This is IMHO useful in a number of idioms. Do you disagree?

Genny.


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