diff --git a/docs/compiler.adoc b/docs/compiler.adoc index 89aa9a8..940be33 100644 --- a/docs/compiler.adoc +++ b/docs/compiler.adoc @@ -6,8 +6,6 @@ provides macros for decorating declarations, which resolve either to keywords or to compiler-specific attributes: * https://clang.llvm.org/docs/AttributeReference.html#always-inline-force-inline[`ALWAYS_INLINE`] -* https://en.cppreference.com/w/cpp/language/consteval[`CONSTEVAL`] -* https://en.cppreference.com/w/cpp/language/constinit[`CONSTINIT`] * https://clang.llvm.org/docs/AttributeReference.html#lifetimebound[`LIFETIMEBOUND`] * https://clang.llvm.org/docs/AttributeReference.html#musttail[`MUSTTAIL`] * https://clang.llvm.org/docs/AttributeReference.html#noinline[`NEVER_INLINE`] diff --git a/include/stdx/bit.hpp b/include/stdx/bit.hpp index 1142717..4cc930b 100644 --- a/include/stdx/bit.hpp +++ b/include/stdx/bit.hpp @@ -403,7 +403,7 @@ template struct bitmask_subtract> { template - 1, std::size_t Lsb = 0> -[[nodiscard]] CONSTEVAL auto bit_mask() noexcept -> T { +[[nodiscard]] consteval auto bit_mask() noexcept -> T { static_assert(Msb < detail::num_digits_v, "bit_mask requested exceeds the range of the type"); static_assert(Msb >= Lsb, "bit_mask range is invalid"); @@ -422,7 +422,7 @@ template constexpr auto bit_size() -> std::size_t { return sizeof(T) * CHAR_BIT; } -template CONSTEVAL auto smallest_uint() { +template consteval auto smallest_uint() { if constexpr (N <= std::numeric_limits::digits) { return std::uint8_t{}; } else if constexpr (N <= std::numeric_limits::digits) { diff --git a/include/stdx/bitset.hpp b/include/stdx/bitset.hpp index 5f9c88f..b897a8e 100644 --- a/include/stdx/bitset.hpp +++ b/include/stdx/bitset.hpp @@ -102,7 +102,7 @@ class bitset { using iter_arg_t = conditional_t, decltype(Size), std::size_t>; - template CONSTEVAL static auto admissible_enum() { + template consteval static auto admissible_enum() { return not std::is_enum_v or std::is_same_v; } diff --git a/include/stdx/call_by_need.hpp b/include/stdx/call_by_need.hpp index 509b066..daef889 100644 --- a/include/stdx/call_by_need.hpp +++ b/include/stdx/call_by_need.hpp @@ -27,14 +27,14 @@ struct call_info { }; template -CONSTEVAL auto truncate_array(std::array const &arr) { +consteval auto truncate_array(std::array const &arr) { return [&](std::index_sequence) { return std::array{arr[Is]...}; }(std::make_index_sequence{}); } template -CONSTEVAL auto concat(std::array const &a1, std::array const &a2) +consteval auto concat(std::array const &a1, std::array const &a2) -> std::array { std::array result{}; auto it = std::copy(std::cbegin(a1), std::cend(a1), std::begin(result)); @@ -64,7 +64,7 @@ constexpr auto invoke(F &&f, Args &&args) -> decltype(auto) { template struct by_need { template - [[nodiscard]] CONSTEVAL static auto compute_call_info_impl() { + [[nodiscard]] consteval static auto compute_call_info_impl() { auto results = std::array{}; auto result_count = std::size_t{}; @@ -108,7 +108,7 @@ template struct by_need { } template - [[nodiscard]] CONSTEVAL static auto compute_call_info() { + [[nodiscard]] consteval static auto compute_call_info() { constexpr auto given_calls = [] { constexpr auto cs = compute_call_info_impl(); return truncate_array(cs.first); diff --git a/include/stdx/compiler.hpp b/include/stdx/compiler.hpp index 5b1c2d0..452cf49 100644 --- a/include/stdx/compiler.hpp +++ b/include/stdx/compiler.hpp @@ -2,34 +2,6 @@ // NOLINTBEGIN(cppcoreguidelines-macro-usage) -#ifndef CONSTINIT -#ifndef __cpp_constinit -#ifdef __clang__ -#define CONSTINIT [[clang::require_constant_initialization]] -#else -#define CONSTINIT -#endif -#else -#define CONSTINIT constinit -#endif -#endif - -#ifndef CONSTEVAL -#ifndef __cpp_consteval -#define CONSTEVAL constexpr -#else -#define CONSTEVAL consteval -#endif -#endif - -#ifndef CONSTEVAL_UDL -#ifdef __clang__ -#define CONSTEVAL_UDL constexpr -#else -#define CONSTEVAL_UDL CONSTEVAL -#endif -#endif - #ifndef USING_ATTR_NS #ifdef __clang__ #define USING_ATTR_NS using clang: @@ -89,7 +61,7 @@ #endif #endif -#ifndef NRVO +#ifndef STDX_NRVO #ifdef __clang__ #define STDX_NRVO(x) std::move(x) #else diff --git a/include/stdx/ct_conversions.hpp b/include/stdx/ct_conversions.hpp index 64ca586..0cd9005 100644 --- a/include/stdx/ct_conversions.hpp +++ b/include/stdx/ct_conversions.hpp @@ -9,7 +9,7 @@ inline namespace v1 { template constexpr bool always_false_v = false; template -CONSTEVAL static auto type_as_string() -> std::string_view { +consteval static auto type_as_string() -> std::string_view { #ifdef __clang__ constexpr std::string_view function_name = __PRETTY_FUNCTION__; constexpr auto rhs = function_name.size() - 2; @@ -26,14 +26,14 @@ CONSTEVAL static auto type_as_string() -> std::string_view { } template -CONSTEVAL static auto template_base() -> std::string_view { +consteval static auto template_base() -> std::string_view { constexpr auto t = stdx::type_as_string(); constexpr auto rhs = t.find('<'); return t.substr(0, rhs); } template -CONSTEVAL static auto enum_as_string() -> std::basic_string_view { +consteval static auto enum_as_string() -> std::basic_string_view { #ifdef __clang__ constexpr std::string_view value_string = __PRETTY_FUNCTION__; #elif defined(__GNUC__) || defined(__GNUG__) diff --git a/include/stdx/ct_format.hpp b/include/stdx/ct_format.hpp index dc99c44..6f9c567 100644 --- a/include/stdx/ct_format.hpp +++ b/include/stdx/ct_format.hpp @@ -36,7 +36,7 @@ struct named_arg { constexpr static std::integral_constant is_runtime{}; template - CONSTEVAL static auto apply_offset() { + consteval static auto apply_offset() { if constexpr (is_runtime) { return named_arg{}; } else { @@ -65,7 +65,7 @@ using apply_offset = template struct format_result { - CONSTEVAL static auto ct_string_convertible() + consteval static auto ct_string_convertible() -> std::bool_constant; [[no_unique_address]] Str str; @@ -92,7 +92,7 @@ struct format_result { template requires(Args::size() == 0 and is_cx_value_v) struct format_result { - CONSTEVAL static auto ct_string_convertible() -> std::true_type; + consteval static auto ct_string_convertible() -> std::true_type; [[no_unique_address]] Str str; [[no_unique_address]] Args args{}; @@ -116,14 +116,14 @@ constexpr auto make_format_result(Str s, Args args = {}) { inline namespace literals { inline namespace ct_string_literals { -template CONSTEVAL_UDL auto operator""_fmt_res() { +template consteval auto operator""_fmt_res() { return make_format_result(cts_t{}); } } // namespace ct_string_literals } // namespace literals namespace detail { -template CONSTEVAL auto find_spec(It first, It last) -> It { +template consteval auto find_spec(It first, It last) -> It { for (auto spec_start = std::find(first, last, '{'); spec_start != last; spec_start = std::find(spec_start, last, '{')) { if (spec_start + 1 != last) { @@ -137,7 +137,7 @@ template CONSTEVAL auto find_spec(It first, It last) -> It { return last; } -CONSTEVAL auto count_specifiers(std::string_view fmt) -> std::size_t { +consteval auto count_specifiers(std::string_view fmt) -> std::size_t { auto count = std::size_t{}; for (auto spec_start = find_spec(fmt.begin(), fmt.end()); spec_start != fmt.end(); @@ -157,7 +157,7 @@ struct split_spec { }; template -CONSTEVAL auto split_specifiers(std::string_view fmt) +consteval auto split_specifiers(std::string_view fmt) -> std::array { auto splits = std::array{}; auto count = std::size_t{}; @@ -182,7 +182,7 @@ CONSTEVAL auto split_specifiers(std::string_view fmt) return splits; } -template CONSTEVAL auto extract_format1_str() { +template consteval auto extract_format1_str() { constexpr auto name_start = Start + 1; constexpr auto it = [] { for (auto i = S.value.cbegin() + name_start; i != S.value.cend(); ++i) { @@ -231,7 +231,7 @@ concept fmt_cx_value = is_cx_value_v or requires(T t) { ct_string_from_type(t); }; template -CONSTEVAL auto arg_value(std::integral_constant) { +consteval auto arg_value(std::integral_constant) { if constexpr (std::is_enum_v) { return enum_as_string(); } else { @@ -239,13 +239,13 @@ CONSTEVAL auto arg_value(std::integral_constant) { } } -template CONSTEVAL auto arg_value(type_identity) { +template consteval auto arg_value(type_identity) { return type_as_string(); } -template CONSTEVAL auto arg_value(cts_t) { return S; } +template consteval auto arg_value(cts_t) { return S; } -CONSTEVAL auto arg_value(fmt_cx_value auto a) { +consteval auto arg_value(fmt_cx_value auto a) { if constexpr (is_specialization_of_v) { return a; } else if constexpr (requires { arg_value(a()); }) { @@ -259,12 +259,12 @@ CONSTEVAL auto arg_value(fmt_cx_value auto a) { } } -template CONSTEVAL auto arg_type(T) -> T; +template consteval auto arg_type(T) -> T; template -CONSTEVAL auto arg_type(std::integral_constant) -> T; +consteval auto arg_type(std::integral_constant) -> T; -CONSTEVAL auto arg_type(fmt_cx_value auto a) { +consteval auto arg_type(fmt_cx_value auto a) { if constexpr (requires { ct_string_from_type(a); }) { return ct_string_from_type(a); } else { @@ -301,11 +301,11 @@ constexpr auto operator+(format_result r1, template struct null_output; -template CONSTEVAL auto to_ct_string(std::string_view s) { +template consteval auto to_ct_string(std::string_view s) { return ct_string{s.data(), s.size()}; } -CONSTEVAL auto convert_input(auto s) { +consteval auto convert_input(auto s) { if constexpr (requires { ct_string_from_type(s); }) { return ct_string_from_type(s); } else { @@ -315,7 +315,7 @@ CONSTEVAL auto convert_input(auto s) { template typename Output = detail::null_output> -CONSTEVAL auto convert_output() { +consteval auto convert_output() { if constexpr (same_as, null_output>) { return cts_t{}; } else { @@ -324,7 +324,7 @@ CONSTEVAL auto convert_output() { } template -CONSTEVAL auto perform_format(auto s, auto const &v) -> ct_string { +consteval auto perform_format(auto s, auto const &v) -> ct_string { ct_string cts{}; fmt::format_to(cts.begin(), s, v); return cts; diff --git a/include/stdx/ct_string.hpp b/include/stdx/ct_string.hpp index 0010028..f6da6a5 100644 --- a/include/stdx/ct_string.hpp +++ b/include/stdx/ct_string.hpp @@ -25,10 +25,10 @@ concept format_convertible = requires(T t) { } // namespace detail template struct ct_string { - CONSTEVAL ct_string() = default; + consteval ct_string() = default; // NOLINTNEXTLINE(*-avoid-c-arrays, google-explicit-constructor) - CONSTEVAL explicit(false) ct_string(char const (&str)[N]) { + consteval explicit(false) ct_string(char const (&str)[N]) { for (auto i = std::size_t{}; i < N; ++i) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-*) value[i] = str[i]; @@ -37,16 +37,16 @@ template struct ct_string { template // NOLINTNEXTLINE(google-explicit-constructor) - CONSTEVAL explicit(false) ct_string(T t) : ct_string(+t) {} + consteval explicit(false) ct_string(T t) : ct_string(+t) {} - CONSTEVAL explicit(true) ct_string(char const *str, std::size_t sz) { + consteval explicit(true) ct_string(char const *str, std::size_t sz) { for (auto i = std::size_t{}; i < sz; ++i) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-*) value[i] = str[i]; } } - CONSTEVAL explicit(true) ct_string(std::string_view str) + consteval explicit(true) ct_string(std::string_view str) : ct_string{str.data(), str.size()} {} [[nodiscard]] constexpr auto begin() LIFETIMEBOUND { return value.begin(); } @@ -86,12 +86,12 @@ template } template