Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/compiler.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`]
4 changes: 2 additions & 2 deletions include/stdx/bit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ template <typename T, std::size_t N> struct bitmask_subtract<std::array<T, N>> {

template <typename T, std::size_t Msb = detail::num_digits_v<T> - 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<T>,
"bit_mask requested exceeds the range of the type");
static_assert(Msb >= Lsb, "bit_mask range is invalid");
Expand All @@ -422,7 +422,7 @@ template <typename T> constexpr auto bit_size() -> std::size_t {
return sizeof(T) * CHAR_BIT;
}

template <std::size_t N> CONSTEVAL auto smallest_uint() {
template <std::size_t N> consteval auto smallest_uint() {
if constexpr (N <= std::numeric_limits<std::uint8_t>::digits) {
return std::uint8_t{};
} else if constexpr (N <= std::numeric_limits<std::uint16_t>::digits) {
Expand Down
2 changes: 1 addition & 1 deletion include/stdx/bitset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class bitset {
using iter_arg_t = conditional_t<std::is_enum_v<decltype(Size)>,
decltype(Size), std::size_t>;

template <typename T> CONSTEVAL static auto admissible_enum() {
template <typename T> consteval static auto admissible_enum() {
return not std::is_enum_v<T> or std::is_same_v<T, decltype(Size)>;
}

Expand Down
8 changes: 4 additions & 4 deletions include/stdx/call_by_need.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ struct call_info {
};

template <std::size_t R, typename T, std::size_t N>
CONSTEVAL auto truncate_array(std::array<T, N> const &arr) {
consteval auto truncate_array(std::array<T, N> const &arr) {
return [&]<std::size_t... Is>(std::index_sequence<Is...>) {
return std::array<T, sizeof...(Is)>{arr[Is]...};
}(std::make_index_sequence<R>{});
}

template <typename T, std::size_t N, std::size_t M>
CONSTEVAL auto concat(std::array<T, N> const &a1, std::array<T, M> const &a2)
consteval auto concat(std::array<T, N> const &a1, std::array<T, M> const &a2)
-> std::array<T, N + M> {
std::array<T, N + M> result{};
auto it = std::copy(std::cbegin(a1), std::cend(a1), std::begin(result));
Expand Down Expand Up @@ -64,7 +64,7 @@ constexpr auto invoke(F &&f, Args &&args) -> decltype(auto) {

template <typename... Fs> struct by_need {
template <typename... Args>
[[nodiscard]] CONSTEVAL static auto compute_call_info_impl() {
[[nodiscard]] consteval static auto compute_call_info_impl() {
auto results = std::array<call_info, sizeof...(Fs) + sizeof...(Args)>{};
auto result_count = std::size_t{};

Expand Down Expand Up @@ -108,7 +108,7 @@ template <typename... Fs> struct by_need {
}

template <typename... Args>
[[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<Args...>();
return truncate_array<cs.second>(cs.first);
Expand Down
30 changes: 1 addition & 29 deletions include/stdx/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -89,7 +61,7 @@
#endif
#endif

#ifndef NRVO
#ifndef STDX_NRVO
#ifdef __clang__
#define STDX_NRVO(x) std::move(x)
#else
Expand Down
6 changes: 3 additions & 3 deletions include/stdx/ct_conversions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ inline namespace v1 {
template <typename...> constexpr bool always_false_v = false;

template <typename Tag>
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;
Expand All @@ -26,14 +26,14 @@ CONSTEVAL static auto type_as_string() -> std::string_view {
}

template <typename T>
CONSTEVAL static auto template_base() -> std::string_view {
consteval static auto template_base() -> std::string_view {
constexpr auto t = stdx::type_as_string<T>();
constexpr auto rhs = t.find('<');
return t.substr(0, rhs);
}

template <auto Value>
CONSTEVAL static auto enum_as_string() -> std::basic_string_view<char> {
consteval static auto enum_as_string() -> std::basic_string_view<char> {
#ifdef __clang__
constexpr std::string_view value_string = __PRETTY_FUNCTION__;
#elif defined(__GNUC__) || defined(__GNUG__)
Expand Down
38 changes: 19 additions & 19 deletions include/stdx/ct_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct named_arg {
constexpr static std::integral_constant<bool, (End < Begin)> is_runtime{};

template <int StringOffset, int ArgOffset>
CONSTEVAL static auto apply_offset() {
consteval static auto apply_offset() {
if constexpr (is_runtime) {
return named_arg<Name, T, Begin + ArgOffset, End + ArgOffset>{};
} else {
Expand Down Expand Up @@ -65,7 +65,7 @@ using apply_offset =

template <typename Str, typename Args, typename NamedArgs>
struct format_result {
CONSTEVAL static auto ct_string_convertible()
consteval static auto ct_string_convertible()
-> std::bool_constant<Args::size() == 0>;

[[no_unique_address]] Str str;
Expand All @@ -92,7 +92,7 @@ struct format_result {
template <typename Str, typename Args, typename NamedArgs>
requires(Args::size() == 0 and is_cx_value_v<Str>)
struct format_result<Str, Args, NamedArgs> {
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{};
Expand All @@ -116,14 +116,14 @@ constexpr auto make_format_result(Str s, Args args = {}) {

inline namespace literals {
inline namespace ct_string_literals {
template <ct_string S> CONSTEVAL_UDL auto operator""_fmt_res() {
template <ct_string S> consteval auto operator""_fmt_res() {
return make_format_result(cts_t<S>{});
}
} // namespace ct_string_literals
} // namespace literals

namespace detail {
template <typename It> CONSTEVAL auto find_spec(It first, It last) -> It {
template <typename It> 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) {
Expand All @@ -137,7 +137,7 @@ template <typename It> 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();
Expand All @@ -157,7 +157,7 @@ struct split_spec {
};

template <std::size_t N>
CONSTEVAL auto split_specifiers(std::string_view fmt)
consteval auto split_specifiers(std::string_view fmt)
-> std::array<split_spec, N> {
auto splits = std::array<split_spec, N>{};
auto count = std::size_t{};
Expand All @@ -182,7 +182,7 @@ CONSTEVAL auto split_specifiers(std::string_view fmt)
return splits;
}

template <ct_string S, std::size_t Start> CONSTEVAL auto extract_format1_str() {
template <ct_string S, std::size_t Start> 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) {
Expand Down Expand Up @@ -231,21 +231,21 @@ concept fmt_cx_value =
is_cx_value_v<T> or requires(T t) { ct_string_from_type(t); };

template <typename T, T V>
CONSTEVAL auto arg_value(std::integral_constant<T, V>) {
consteval auto arg_value(std::integral_constant<T, V>) {
if constexpr (std::is_enum_v<T>) {
return enum_as_string<V>();
} else {
return V;
}
}

template <typename T> CONSTEVAL auto arg_value(type_identity<T>) {
template <typename T> consteval auto arg_value(type_identity<T>) {
return type_as_string<T>();
}

template <ct_string S> CONSTEVAL auto arg_value(cts_t<S>) { return S; }
template <ct_string S> consteval auto arg_value(cts_t<S>) { 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<decltype(a), format_result>) {
return a;
} else if constexpr (requires { arg_value(a()); }) {
Expand All @@ -259,12 +259,12 @@ CONSTEVAL auto arg_value(fmt_cx_value auto a) {
}
}

template <typename T> CONSTEVAL auto arg_type(T) -> T;
template <typename T> consteval auto arg_type(T) -> T;

template <typename T, T V>
CONSTEVAL auto arg_type(std::integral_constant<T, V>) -> T;
consteval auto arg_type(std::integral_constant<T, V>) -> 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 {
Expand Down Expand Up @@ -301,11 +301,11 @@ constexpr auto operator+(format_result<Str1, Args1, NamedArgs1> r1,

template <typename T, T...> struct null_output;

template <std::size_t Sz> CONSTEVAL auto to_ct_string(std::string_view s) {
template <std::size_t Sz> consteval auto to_ct_string(std::string_view s) {
return ct_string<Sz + 1>{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 {
Expand All @@ -315,7 +315,7 @@ CONSTEVAL auto convert_input(auto s) {

template <ct_string S,
template <typename T, T...> typename Output = detail::null_output>
CONSTEVAL auto convert_output() {
consteval auto convert_output() {
if constexpr (same_as<Output<char>, null_output<char>>) {
return cts_t<S>{};
} else {
Expand All @@ -324,7 +324,7 @@ CONSTEVAL auto convert_output() {
}

template <std::size_t N>
CONSTEVAL auto perform_format(auto s, auto const &v) -> ct_string<N + 1> {
consteval auto perform_format(auto s, auto const &v) -> ct_string<N + 1> {
ct_string<N + 1> cts{};
fmt::format_to(cts.begin(), s, v);
return cts;
Expand Down
24 changes: 11 additions & 13 deletions include/stdx/ct_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ concept format_convertible = requires(T t) {
} // namespace detail

template <std::size_t N> 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];
Expand All @@ -37,16 +37,16 @@ template <std::size_t N> struct ct_string {

template <detail::format_convertible T>
// 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(); }
Expand Down Expand Up @@ -86,12 +86,12 @@ template <std::size_t N, std::size_t M>
}

template <template <typename C, C...> typename T, char... Cs>
[[nodiscard]] CONSTEVAL auto ct_string_from_type(T<char, Cs...>) {
[[nodiscard]] consteval auto ct_string_from_type(T<char, Cs...>) {
return ct_string<sizeof...(Cs) + 1U>{{Cs..., 0}};
}

template <ct_string S, template <typename C, C...> typename T>
[[nodiscard]] CONSTEVAL auto ct_string_to_type() {
[[nodiscard]] consteval auto ct_string_to_type() {
return [&]<auto... Is>(std::index_sequence<Is...>) {
return T<char, std::get<Is>(S.value)...>{};
}(std::make_index_sequence<S.size()>{});
Expand Down Expand Up @@ -141,7 +141,7 @@ template <ct_string S> struct cts_t {
using value_type = decltype(S);
constexpr static auto value = S;

CONSTEVAL static auto ct_string_convertible() -> std::true_type;
consteval static auto ct_string_convertible() -> std::true_type;
friend constexpr auto operator+(cts_t const &) { return value; }
constexpr auto operator()() const noexcept { return value; }
using cx_value_t [[maybe_unused]] = void;
Expand Down Expand Up @@ -172,17 +172,15 @@ namespace detail {
template <std::size_t N> struct ct_helper<ct_string<N>>;
} // namespace detail

template <ct_string Value> CONSTEVAL auto ct() { return cts_t<Value>{}; }
template <ct_string Value> consteval auto ct() { return cts_t<Value>{}; }

template <ct_string Value> constexpr auto is_ct_v<cts_t<Value>> = true;

inline namespace literals {
inline namespace ct_string_literals {
template <ct_string S> CONSTEVAL_UDL auto operator""_cts() { return S; }
template <ct_string S> consteval auto operator""_cts() { return S; }

template <ct_string S> CONSTEVAL_UDL auto operator""_ctst() {
return cts_t<S>{};
}
template <ct_string S> consteval auto operator""_ctst() { return cts_t<S>{}; }
} // namespace ct_string_literals
} // namespace literals
} // namespace v1
Expand Down
Loading
Loading