Skip to content

sssersh/too_constexpr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CANT

Constexpr allocations (non transient)


C++20-compatible library which implements constexpr non-transient allocator for standard containers.

Now it supports std::string and std::vector (just because there is no other dynamic constexpr containers in standard library)

Compilers support:

Now there is convinient way to construct strings and vectors at compile time:

constexpr std::string_view str1 = "It is string which was builded ";
constexpr std::string_view str2 = "as concatenation of two strings";

constexpr auto concat_result = 
    cant::too_constexpr(
        []() -> std::string
        {
            return std::string(str1) + std::string(str2);
        }
);

// It does work!
static_assert(concat_result == "It is string which was builded as concatenation of two strings", "error");

How to use

It's necessary to pass functional object (lambda, for example) which produce result to function cant::too_constexpr.

Limitations

  • Lamda passed to cant::too_constexpr must NOT:

    • have any arguments (arguments with default values is possible)
    • capture any objects
  • It should use only other constexpr objects.

  • Nested containers e.g. std::vector<std::string>, now is not supported.

Build examples

mkdir build
cd build
cmake ..
cmake --build .

Examples require C++23 standard, because it contain example with std::unordered_map.

Other examples can work with C++20.

Possible errors


Clang

If your constexpr object is too big and you get compile error which looks like ...constexpr evaluation hit maximum step limit..., just increase constexpr steps by adding flat -fconstexpr-steps=N.

Future

  • support nested containers
  • improve compile time

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published