Skip to content

String type that can be evaluated in a constant context, with limited reflection support

License

Notifications You must be signed in to change notification settings

NichtsHsu/conststr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Conststr

Operate strings in constant context.

NOTE: Your compiler must support C++20.

For example:

#include "conststr.hpp"
 
using conststr::cstr;
using namespace conststr::literal;

constexpr auto hello = "hello"_cs;
constexpr auto world = "world"_cs;
constexpr auto msg = hello + ' ' + world + '!';

static_assert(msg == "hello world!"_cs);

constexpr auto newmsg = msg.uppercase()    // to "HELLO WORLD!"
                            .pop()         // to "HELLO WORLD"
                            .erase(4)      // to "HELL WORLD"
                            .erase(8)      // to "HELL WORD"
                            .append('?');  // to "HELL WORD?"

static_assert(newmsg == "HELL WORD?"_cs);

Check the document or tests to learn more.

All tests passed under GCC-12, Clang-14 and MSVC(newest). Maybe lower versions can also pass the tests, but I haven't tested them and will never guarantee compatibility.

About

String type that can be evaluated in a constant context, with limited reflection support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published