Using Strings in C++ Template Metaprograms -- Abel Sinkovics and Dave Abrahams

Fresh off the press at C++ Next:

Using strings in C++ template metaprograms

by Abel Sinkovics and Dave Abrahams

Of all the reasons to love metaprogramming, probably the most compelling is that it lets us embed “little languages” in our programs... Instead of C++ expressions, of course, strings could be used to represent the DSL code snippet in the embedding C++ code. In fact, that’s an approach used by many “traditional” libraries:

auto all_caps = std::regex("[A-Z]+"); // OK

The only problem is, the contents of that string are only known at runtime, which means the language has to be interpreted at runtime, and we lose the benefit of being able to translate the structure into compiled code. The “delayed evaluation” has been delayed too long.

If, however, these strings could be parsed at compile-time, the resulting programs could have optimal performance again...

[more]

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.