Boost logo

Boost :

Subject: Re: [boost] Compile Time String in C++14
From: Mikael Persson (mikael.s.persson_at_[hidden])
Date: 2014-08-26 20:24:27


I also fail to see the advantage of this implementation. I mean, it still
uses index_sequence (or, in the first version, a variadic template
parameter pack of chars), which is the main problem with using compile-time
strings; it's the common problem in most real constexpr string
implementations, as far I as know. An implementation of a constexpr string
class that would avoid forming this type of very costly (non-scalable)
template instantiation is starting to become interesting from a usability
point of view, but short of that, it's hard to justify using it for
anything but trivial tasks. That was just a remark.

And as Paul remarks, you have obviously omitted the "constexpr" specifier
in many places.

So, can you explain how your implementation differs or improves upon
existing constexpr string implementations?

Here is a short list of existing compile-time string implementations (in
case some people reading this are not familiar with the options available
to solve that problem):

Scott Schurr's very simple demo of "str_const":
https://github.com/boostcon/cppnow_presentations_2012/blob/master/wed/schurr_cpp11_tools_for_class_authors.pdf?raw=true

Which is very similar (and better explained) to Andrzej Krzemienski's
"StrWrap":
http://akrzemi1.wordpress.com/2011/05/11/parsing-strings-at-compile-time-part-i/

Or Sprout's very comprehensive implementation (basically a compile-time
implementation of std::string):
https://github.com/bolero-MURAKAMI/Sprout/blob/master/sprout/string/string.hpp

Or yet again, my own more light-weight version which supports compile-time
concatenation, hashing and int-to-string functions only:
https://github.com/mikael-s-persson/ReaK/blob/pp_dev/src/ReaK/core/base/cnst_string.hpp

which I explain in more details here (warning: it's a bit more of a
tutorial for beginners, not aimed at experts):
https://www.daniweb.com/software-development/cpp/code/482276/c11-compile-time-string-concatenation-with-constexpr

@ Abel:

> So the way I'd use it would be something like:
> ...
> Did you manage to use these strings as template arguments somehow?

AFAIK, you can use any of the above-listed implementations of constexpr
strings in the way that you showed, but not the one discussed here.

Compile-time strings are not a new thing, they are simply not very
practical because they cause so much compilation overhead (because of
compile-time char-by-char operations, deep compile-time recursions, and
costly template instantiations), IMHO.

Cheers,
Mikael Persson.


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