25#ifndef JAU_CPP_LANG_EXT_HPP_
26#define JAU_CPP_LANG_EXT_HPP_
82#if __cplusplus > 201703L
83 #define consteval_cxx20 consteval
85 #define consteval_cxx20 constexpr
90 #if __cplusplus > 201402L
98 #if __cplusplus > 201703L
106 #if __cplusplus > 202002L
114 #if __cplusplus > 202302L
139#if __cplusplus > 201703L
140 #define constinit_cxx20 constinit
142 #define constinit_cxx20 constexpr
158#if __cplusplus > 201703L
159 #define constexpr_cxx20 constexpr
161 #define constexpr_cxx20 inline
164#if __cplusplus > 202002L
165 #define constexpr_cxx23 constexpr
167 #define constexpr_cxx23 inline
170#if __cplusplus > 202302L
171 #define constexpr_cxx26 constexpr
173 #define constexpr_cxx26 inline
194 #define constexpr_non_literal_var constexpr_cxx23
211 #define constexpr_atomic constexpr_cxx23
216 #if defined(__clang__)
217 #define __restrict_cxx__ __restrict__
218 #elif defined(__GNUC__) && !defined(__clang__)
219 #define __restrict_cxx__ __restrict__
220 #elif defined(_MSC_VER)
221 #define __restrict_cxx__ __restrict
223 #define __restrict_cxx__
226 #if defined(__clang__)
228 #define JAU_PRETTY_FUNCTION __PRETTY_FUNCTION__
229 #elif defined(__GNUC__) && !defined(__clang__)
231 #define JAU_PRETTY_FUNCTION __PRETTY_FUNCTION__
232 #elif defined(_MSC_VER)
234 #define JAU_PRETTY_FUNCTION __FUNCSIG__
236 #error "JAU_PRETTY_FUNCTION not available"
256 std::string
demangle_name(
const char* mangled_name)
noexcept;
258 #if defined(__clang__)
261 #elif defined(__GNUC__) && !defined(__clang__)
263 #define final_opt final
264 #elif defined(_MSC_VER)
266 #define final_opt final
269 #define final_opt final
285 template <
typename Dummy_type>
287 #if defined __has_builtin && __has_builtin(__builtin_bit_cast)
324 #if defined __has_builtin && __has_builtin(__builtin_bit_cast)
349 template <
class Dest,
class Source>
351 typename std::enable_if_t<
352 sizeof(Dest) ==
sizeof(Source) &&
353 std::is_pointer_v<Source> &&
354 std::is_pointer_v<Dest>,
359 return __builtin_bit_cast(Dest, src);
362 return reinterpret_cast<Dest
>(
const_cast< std::remove_const_t< std::remove_pointer_t<Source>
>* >( src ) );
379 template <
class Dest,
class Source>
381 typename std::enable_if_t<
382 sizeof(Dest) ==
sizeof(Source) &&
383 std::is_trivially_copyable_v<Dest> &&
384 std::is_trivially_copyable_v<Source>,
389 return __builtin_bit_cast(Dest, src);
396 #if defined(__SIZEOF_INT128__)
403 #if defined(__SIZEOF_INT128__)
405 #if defined(__GNUG__)
406 typedef int int128_t __attribute__((mode(TI)));
407 typedef unsigned int uint128_t __attribute__((mode(TI)));
409 typedef __int128 int128_t;
410 typedef unsigned __int128 uint128_t;
416 #if defined(NDEBUG) && !defined(DEBUG)
423 #if defined(__clang__)
424 #define __attrdecl_no_optimize__ __attribute__ ((optnone))
425 #define __attrdef_no_optimize__ __attribute__ ((optnone))
426 #elif defined(__GNUC__) && !defined(__clang__)
427 #define __attrdecl_no_optimize__ __attribute__((optimize("O0")))
429 #define __attrdef_no_optimize__
431 #define __attrdecl_no_optimize__
432 #define __attrdef_no_optimize__
438 template <
typename UnaryFunc>
441 asm volatile(
"" :
"+r,m"(f) : :
"memory");
454 return static_cast<bool>(rhs);
457 return static_cast<bool>(rhs);
463 return Bool(*lhs && *rhs);
466 return Bool(*lhs || *rhs);
469 return Bool(*lhs ^ *rhs);
472 return Bool(*lhs || *rhs);
475 return Bool(*lhs && *rhs);
492 constexpr std::string_view
name(
const Bool v)
noexcept {
std::string to_string(const endian_t v) noexcept
Return std::string representation of the given endian.
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 & 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).
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.
std::ostream & operator<<(std::ostream &out, const cow_darray< Value_type, Size_type, Alloc_type > &c)
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
bool operator==(const callocator< T1 > &lhs, const callocator< T2 > &rhs) noexcept
Convenience type trait for __has_builtin(__builtin_bit_cast).