Boost logo

Boost Users :

Subject: Re: [Boost-users] compile-time string literal manipulation?
From: Dominique Devienne (ddevienne_at_[hidden])
Date: 2010-10-29 12:24:53


On Fri, Oct 29, 2010 at 11:04 AM, Cromwell Enage <sponage_at_[hidden]> wrote:
>> Why would it not be
>> typedef mpl::string<'h','e','l','l','o',' ','w','o','r','l','d'> hello;
> I would think this was correct, as well.

It probably is, but uses more template parameters, probably leading to
longer compile time and bigger pre-processed code (just guesses, I'm
no expert). It's also longer to type :)

>> OR if the example is correct, why could you not simply do
>> typedef mpl::string<'hello world'> hello;

Because that's invalid.

> Non-type template arguments can only be constant integers or (maybe in this case) multi-byte characters.  A four-byte character value might be the standard limit here. [...]

As [1] points out, using 'abcd' is a "fairly unknown—and arguably
somewhat implementation-defined—existence of multi-character literals"
feature of C++. [2] further points to STD 6.4.4.4p10 stating it is
indeed implementation-defined. But Eric Niebler
(templatr-extraordinaire), made it work for known compilers. So yes
it's a bit weird at first, but it just works! --DD

[1] http://arcticinteractive.com/2009/04/18/compile-time-string-hashing-boost-mpl/
[2] http://bytes.com/topic/c/answers/739845-multi-character-constant


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net