Skip to content

Latest commit

 

History

History
32 lines (21 loc) · 1.06 KB

README.md

File metadata and controls

32 lines (21 loc) · 1.06 KB

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.