25#ifndef JAU_CPP_LANG_EXT_HPP_
26#define JAU_CPP_LANG_EXT_HPP_
34#if __cplusplus > 201703L
38#if __cplusplus > 202002L
93#if __cplusplus > 201703L
94 #define consteval_cxx20 consteval
96 #define consteval_cxx20 constexpr
101 #if __cplusplus > 201402L
109 #if __cplusplus > 201703L
117 #if __cplusplus > 202002L
125 #if __cplusplus > 202302L
150#if __cplusplus > 201703L
151 #define constinit_cxx20 constinit
153 #define constinit_cxx20 constexpr
169#if __cplusplus > 201703L
170 #define constexpr_cxx20 constexpr
172 #define constexpr_cxx20 inline
175#if __cplusplus > 202002L
176 #define constexpr_cxx23 constexpr
178 #define constexpr_cxx23 inline
181#if __cplusplus > 202302L
182 #define constexpr_cxx26 constexpr
184 #define constexpr_cxx26 inline
205 #define constexpr_non_literal_var constexpr_cxx23
222 #define constexpr_atomic constexpr_cxx23
227 #if defined(__clang__)
228 #define __restrict_cxx__ __restrict__
229 #elif defined(__GNUC__) && !defined(__clang__)
230 #define __restrict_cxx__ __restrict__
231 #elif defined(_MSC_VER)
232 #define __restrict_cxx__ __restrict
234 #define __restrict_cxx__
237 #if defined(__clang__)
239 #define JAU_PRETTY_FUNCTION __PRETTY_FUNCTION__
240 #elif defined(__GNUC__) && !defined(__clang__)
242 #define JAU_PRETTY_FUNCTION __PRETTY_FUNCTION__
243 #elif defined(_MSC_VER)
245 #define JAU_PRETTY_FUNCTION __FUNCSIG__
247 #error "JAU_PRETTY_FUNCTION not available"
267 std::string
demangle_name(
const char* mangled_name)
noexcept;
269 #if defined(__clang__)
272 #elif defined(__GNUC__) && !defined(__clang__)
274 #define final_opt final
275 #elif defined(_MSC_VER)
277 #define final_opt final
280 #define final_opt final
296 template <
typename Dummy_type>
298 #if defined __has_builtin && __has_builtin(__builtin_bit_cast)
335 #if defined __has_builtin && __has_builtin(__builtin_bit_cast)
360 template <
class Dest,
class Source>
362 typename std::enable_if_t<
363 sizeof(Dest) ==
sizeof(Source) &&
364 std::is_pointer_v<Source> &&
365 std::is_pointer_v<Dest>,
370 return std::bit_cast<Dest, Source>(src);
372 return __builtin_bit_cast(Dest, src);
375 return reinterpret_cast<Dest
>(
const_cast< std::remove_const_t< std::remove_pointer_t<Source>
>* >( src ) );
392 template <
class Dest,
class Source>
394 typename std::enable_if_t<
395 sizeof(Dest) ==
sizeof(Source) &&
396 std::is_trivially_copyable_v<Dest> &&
397 std::is_trivially_copyable_v<Source>,
402 return std::bit_cast<Dest, Source>(src);
404 return __builtin_bit_cast(Dest, src);
411 #if defined(__SIZEOF_INT128__)
418 #if defined(__SIZEOF_INT128__)
420 #if defined(__GNUG__)
421 typedef int int128_t __attribute__((mode(TI)));
422 typedef unsigned int uint128_t __attribute__((mode(TI)));
424 typedef __int128 int128_t;
425 typedef unsigned __int128 uint128_t;
431 #if defined(NDEBUG) && !defined(DEBUG)
438 #if defined(__clang__)
439 #define __attrdecl_no_optimize__ __attribute__ ((optnone))
440 #define __attrdef_no_optimize__ __attribute__ ((optnone))
441 #elif defined(__GNUC__) && !defined(__clang__)
442 #define __attrdecl_no_optimize__ __attribute__((optimize("O0")))
444 #define __attrdef_no_optimize__
446 #define __attrdecl_no_optimize__
447 #define __attrdef_no_optimize__
453 template <
typename UnaryFunc>
456 asm volatile(
"" :
"+r,m"(
f) : :
"memory");
470 return static_cast<bool>(rhs);
473 return static_cast<bool>(rhs);
479 return Bool(*lhs && *rhs);
482 return Bool(*lhs || *rhs);
485 return Bool(*lhs ^ *rhs);
488 return Bool(*lhs || *rhs);
491 return Bool(*lhs && *rhs);
508 constexpr std::string_view
name(
const Bool v)
noexcept {
534 for (
size_t i = 0; i < N; ++i) {
buf[i] = str[i]; }
consteval_cxx20 StringLiteral(StringLiteral &&o) noexcept=default
consteval_cxx20 StringLiteral(const char(&str)[N]) noexcept
consteval_cxx20 size_t size() const noexcept
Returns string literal size w/o EOS.
consteval_cxx20 StringLiteral & operator=(StringLiteral &&o) noexcept=default
consteval_cxx20 StringLiteral & operator=(const StringLiteral &o) noexcept=delete
consteval_cxx20 char const * c_str() const noexcept
Returns c-string w/ EOS.
consteval_cxx20 StringLiteral(const StringLiteral &o) noexcept=delete
consteval_cxx20 std::string_view view() const noexcept
Returns string_view.
std::ostream & operator<<(std::ostream &out, const bitfield_t< StorageType, BitSize > &v)
consteval_cxx20 bool is_builtin_int128_available() noexcept
constexpr bool value(const Bool rhs) noexcept
constexpr bool operator*(const Bool rhs) noexcept
constexpr Bool & operator&=(Bool &lhs, const Bool rhs) noexcept
constexpr Bool makeBool(bool v) noexcept
constexpr Bool & operator^=(Bool &lhs, const Bool rhs) noexcept
consteval_cxx20 bool is_cxx23() noexcept
Returns true if compiled with >= C++23.
void callNotOptimize(UnaryFunc f) __attrdef_no_optimize__
Simple unary function wrapper which ensures function call to happen in order and not optimized away.
consteval_cxx20 bool is_cxx20() noexcept
Returns true if compiled with >= C++20.
constexpr bool has_builtin_bit_cast_v
Value access of has_builtin_bit_cast type trait for convenience .
constexpr Bool False() noexcept
constexpr Bool operator^(const Bool lhs, const Bool rhs) noexcept
consteval_cxx20 bool is_cxx17() noexcept
Returns true if compiled with >= C++17.
constexpr Bool operator|(const Bool lhs, const Bool rhs) noexcept
constexpr Bool True() noexcept
constexpr std::enable_if_t< sizeof(Dest)==sizeof(Source) &&std::is_trivially_copyable_v< Dest > &&std::is_trivially_copyable_v< Source >, Dest > bit_cast(const Source &src) noexcept
C++20 bit_cast<>(arg) implementation for C++17.
consteval_cxx20 bool is_debug_enabled() noexcept
Returns true if compiled with debug information and w/o optimization, i.e.
constexpr Bool operator&(const Bool lhs, const Bool rhs) noexcept
constexpr Bool operator&&(const Bool lhs, const Bool rhs) noexcept
constexpr Bool & operator|=(Bool &lhs, const Bool rhs) noexcept
consteval_cxx20 bool has_builtin_bit_cast() noexcept
Query whether __builtin_bit_cast(Dest_type, arg) is available via __has_builtin(__builtin_bit_cast).
constexpr std::enable_if_t< sizeof(Dest)==sizeof(Source) &&std::is_pointer_v< Source > &&std::is_pointer_v< Dest >, Dest > pointer_cast(const Source &src) noexcept
A constexpr pointer cast implementation for C++17, inspired by C++20 bit_cast<>(arg).
consteval_cxx20 void consteval_assert(bool v)
constexpr Bool operator||(const Bool lhs, const Bool rhs) noexcept
std::string demangle_name(const char *mangled_name) noexcept
Returns the demangled given mangled_name if successful, otherwise the mangled_name.
#define __attrdef_no_optimize__
constexpr std::string_view name(const Bool v) noexcept
constexpr Bool operator!(const Bool rhs) noexcept
#define consteval_cxx20
consteval qualifier replacement for C++20 consteval.
consteval_cxx20 bool is_cxx26() noexcept
Returns true if compiled with >= C++26.
Bool
Boolean type without implicit conversion, safe for function parameter.
bool runtime_eval(bool v)
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
bool operator==(const callocator< T1 > &lhs, const callocator< T2 > &rhs) noexcept
std::string to_string(const bit_order_t v) noexcept
Return std::string representation of the given bit_order_t.
Convenience type trait for __has_builtin(__builtin_bit_cast).
static std::string f(uint32_t v)