diff --git a/const_fmt/stdlib.h b/const_fmt/stdlib.h index 5444b7a..0e46a93 100644 --- a/const_fmt/stdlib.h +++ b/const_fmt/stdlib.h @@ -36,6 +36,13 @@ using size_t = uint16_t; */ +// various + + +constexpr inline bool is_constant_evaluated() noexcept { + return __builtin_is_constant_evaluated(); +} + struct true_type { constexpr static bool value = true; }; @@ -45,6 +52,35 @@ struct false_type { }; +// is_same + + +template +struct is_same : public false_type {}; + +template +struct is_same : public false_type {}; + + +// is_one_of + + +template +struct is_one_of; +template +struct is_one_of { + constexpr static bool value = false; +}; +template +struct is_one_of { + constexpr static bool value = std::is_same::value || + is_one_of::value; +}; + + +// remove_x + + // clang-format off template struct remove_cv { typedef type_t type; }; @@ -67,46 +103,36 @@ template using remove_cv_t = typename std::remove_cv using remove_const_t = typename std::remove_const::type; template using remove_volatile_t = typename std::remove_volatile::type; +// clang-format on -template struct is_integral_helper : public false_type {}; -template <> struct is_integral_helper : public true_type {}; -template <> struct is_integral_helper : public true_type {}; -template <> struct is_integral_helper : public true_type {}; -template <> struct is_integral_helper : public true_type {}; -template <> struct is_integral_helper : public true_type {}; -template <> struct is_integral_helper : public true_type {}; -template <> struct is_integral_helper : public true_type {}; -template <> struct is_integral_helper : public true_type {}; -template <> struct is_integral_helper : public true_type {}; -template <> struct is_integral_helper : public true_type {}; -template <> struct is_integral_helper : public true_type {}; -template <> struct is_integral_helper : public true_type {}; -template <> struct is_integral_helper : public true_type {}; -template <> struct is_integral_helper : public true_type {}; -template <> struct is_integral_helper : public true_type {}; +// is_integral + template -struct is_integral - : public is_integral_helper> {}; +struct is_integral { + constexpr static bool value = + is_one_of, bool, char, signed char, unsigned char, + wchar_t, char16_t, char32_t, short, unsigned short, int, + unsigned int, long, unsigned long, long long, + unsigned long long>::value; +}; -template struct is_floating_point_helper : public false_type {}; - -template<> struct is_floating_point_helper : public true_type {}; -template<> struct is_floating_point_helper : public true_type {}; -template<> struct is_floating_point_helper : public true_type {}; - -template -struct is_floating_point - : public is_floating_point_helper>::type {}; +// is_floating_point +template +struct is_floating_point { + constexpr static bool value = + is_one_of, float, double, long double>::value; +}; -constexpr inline bool is_constant_evaluated() noexcept { - return __builtin_is_constant_evaluated(); -} +// make_unsigned + + +// clang-format off template struct make_unsigned { using type = type_t; }; @@ -147,7 +173,7 @@ template <> struct make_unsigned { using type = unsigned long template -void copy(input_t* start, input_t* end, output_t* dest_start) { +constexpr inline void copy(input_t* start, input_t* end, output_t* dest_start) { memcpy(start, dest_start, end - start); } @@ -165,7 +191,7 @@ std::remove_reference_t&& move(T&& arg) noexcept { } template -void swap(T& t1, T& t2) { +constexpr inline void swap(T& t1, T& t2) { T temp = std::move(t1); t1 = std::move(t2); t2 = std::move(temp);