Boost logo

Boost :

From: Robert Klarer (klarer_at_[hidden])
Date: 2003-03-03 11:06:33


There was some discussion among the extensions subgroup of the C++ standard
committee about the question of how the language might be extended to allow string
literals to be used as template arguments. That discussion was inconclusive.

It seems to me that the root of the problem is that C-style strings, and hence
string literals, are not first-class builtin types in C++. I've been
experimenting with one possible solution to that problem: I've (partially)
implemented a "static_string" library and uploaded it to the 'Files' section of
Boost's Yahoo Group. Here is the abstract from the (also partial) introductory
document:

"The static_string C++ library is an alternative to both string literals and the
standard C++ type const std::basic_string<char>. Any operation that can be
performed upon a const std::basic_string<char> object at runtime can be performed
by the static_string library. Furthermore, the static_string library implements a
number of metafunctions that allow these operations to be performed at program
compile time. The static_string library is significantly more efficient in its use
of both time and space than const std::basic_string<char>."

The static_string library allows strings to be represented by types, so that they
can be used as template arguments.

The syntax for using static_string is awkward, but a language extension that would
make a library like static_string convenient to use might be worth considering as
an alternative to the wholesale introduction of
string-literals-as-template-arguments to the core language.

A woefully incomplete version of the static_string library can be found at:
http://groups.yahoo.com/group/boost/files/static_string.zip


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