A structurally modernized fork of elbeno/constexpr suited for library use. Some libraries that did not compile on modern clang and gcc have been disabled and moved to the legacy directory. Tests fail to compile on windows, so use with caution.
To add this library to your project, simply use CPM.cmake.
CPMAddPackage(
NAME constexpr
GITHUB_REPOSITORY TheLartians/constexpr
GIT_TAG 0e2279142d7e4f6631659f90894bd7dbb24d082a
)
Everything (with the exception of noted functions) is written in C++11 constexpr style for maximum compatibility.
All functions are within the cx
namespace.
This code is distributed under the MIT license. See LICENSE for details.
abs
,fabs
sqrt
,cbrt
,hypot
exp
,log
,log10
,log2
sin
,cos
,tan
asin
,acos
,atan
,atan2
floor
,ceil
,trunc
,round
(long double variants require C++14)fmod
,remainder
(long double variants require C++14)fmin
,fmax
,fdim
sinh
,cosh
,tanh
asinh
,acosh
,atanh
pow
erf
fnv1
,fnv1a
murmur3_32
md5
sha256
strlen
strcmp
endianswap
counter
: returns monotonically increasing integers with each call (within a given translation unit)
cx_pcg32
: a macro that returns a different randomuint32_t
with each callcx_guidgen
: a macro that generates a different random GUID with each call
String encryption uses std::make_index_sequence
therefore requires C++14.
cx_make_encrypted_string
: a macro that encrypts a string literal, with a runtime conversion to plaintextstd::string
Arrays use std::make_index_sequence
therefore require C++14.
array<type, size>
: a constexpr-friendly array typemake_array
: create anarray
from e.g. a string literaltransform
: likestd::transform
but works on constexprarray
sreverse
sort
: an implementation of mergesort (stable)partition
: a stable partition (but usecount_if
to obtain the partition point)
accumulate
: likestd::accumulate
but works on constexprarray
s
Similarly:
all_of
,any_of
,none_of
count
,count_if
find
,find_if
, find_if_not`equal
,mismatch
find_first_of
adjacent_find
search
,search_n
inner_product