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
18 changes: 11 additions & 7 deletions include/stdx/bit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,13 @@ template <typename To, typename From> constexpr auto bit_unpack(From arg) {
"bit_unpack is undefined for those types");

constexpr auto sz = sized<From>{1}.template in<To>();
auto r = bit_cast<std::array<To, sz>>(to_be(arg));
for (auto &elem : r) {
elem = from_be(elem);
}
return r;
return [&]() -> std::array<To, sz> {
auto r = bit_cast<std::array<To, sz>>(to_be(arg));
for (auto &elem : r) {
elem = from_be(elem);
}
return r;
}();
}

namespace detail {
Expand Down Expand Up @@ -436,14 +438,16 @@ template <std::size_t N> using smallest_uint_t = decltype(smallest_uint<N>());

namespace bit_detail {
template <std::size_t... Offsets>
constexpr auto shifts = [] {
constexpr auto shifts =
[]() -> std::array<std::size_t, sizeof...(Offsets) + 1> {
constexpr auto offsets = std::array{std::size_t{}, Offsets...};
auto s = std::array<std::size_t, sizeof...(Offsets) + 1>{};
for (auto i = std::size_t{}; i < sizeof...(Offsets); ++i) {
s[i + 1] = offsets[i + 1] - offsets[i];
}
return s;
}();
}
();

template <std::size_t Shift, std::size_t Msb, typename T>
constexpr auto shift_extract(T &t) -> T {
Expand Down
20 changes: 12 additions & 8 deletions include/stdx/ct_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ CONSTEVAL auto count_specifiers(std::string_view fmt) -> std::size_t {
return count;
}

template <std::size_t N> CONSTEVAL auto split_specifiers(std::string_view fmt) {
template <std::size_t N>
CONSTEVAL auto split_specifiers(std::string_view fmt)
-> std::array<std::string_view, N> {
auto splits = std::array<std::string_view, N>{};
auto count = std::size_t{};

Expand Down Expand Up @@ -196,24 +198,26 @@ CONSTEVAL auto convert_output() {
}
}

template <std::size_t N>
CONSTEVAL auto perform_format(auto s, auto v) -> ct_string<N + 1> {
ct_string<N + 1> cts{};
fmt::format_to(cts.begin(), s, v);
return cts;
}

template <ct_string Fmt, typename Arg> constexpr auto format1(Arg arg) {
if constexpr (requires { arg_value(arg); }) {
constexpr auto fmtstr = FMT_COMPILE(std::string_view{Fmt});
constexpr auto a = arg_value(arg);
auto const f = []<std::size_t N>(auto s, auto v) {
ct_string<N + 1> cts{};
fmt::format_to(cts.begin(), s, v);
return cts;
};
if constexpr (is_specialization_of_v<std::remove_cv_t<decltype(a)>,
format_result>) {
constexpr auto s = convert_input(a.str);
constexpr auto sz = fmt::formatted_size(fmtstr, s);
constexpr auto cts = f.template operator()<sz>(fmtstr, s);
constexpr auto cts = perform_format<sz>(fmtstr, s);
return format_result{cts_t<cts>{}, a.args};
} else {
constexpr auto sz = fmt::formatted_size(fmtstr, a);
constexpr auto cts = f.template operator()<sz>(fmtstr, a);
constexpr auto cts = perform_format<sz>(fmtstr, a);
return format_result{cts_t<cts>{}};
}
} else if constexpr (is_specialization_of_v<Arg, format_result>) {
Expand Down
18 changes: 10 additions & 8 deletions include/stdx/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,16 @@ struct tuple_impl<std::index_sequence<Is...>, index_function_list<Fs...>, Ts...>
using C =
std::common_comparison_category_t<decltype(lhs[index<Is>] <=>
rhs[index<Is>])...>;
C result = lhs[index<0>] <=> rhs[index<0>];
auto const compare_at = [&]<std::size_t I>() {
result = lhs[index<I>] <=> rhs[index<I>];
return result != 0;
};
[[maybe_unused]] auto b =
(compare_at.template operator()<Is>() or ...);
return result;
return [&]() -> C {
C result = lhs[index<0>] <=> rhs[index<0>];
auto const compare_at = [&]<std::size_t I>() {
result = lhs[index<I>] <=> rhs[index<I>];
return result != 0;
};
[[maybe_unused]] auto b =
(compare_at.template operator()<Is>() or ...);
return result;
}();
}
}
};
Expand Down
19 changes: 11 additions & 8 deletions include/stdx/tuple_algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ template <typename F, tuplelike... Ts> constexpr auto apply(F &&f, Ts &&...ts) {
constexpr auto total_num_elements =
(std::size_t{} + ... + stdx::tuple_size_v<std::remove_cvref_t<Ts>>);

[[maybe_unused]] constexpr auto element_indices = [&] {
[[maybe_unused]] constexpr auto element_indices =
[&]() -> std::array<detail::index_pair, total_num_elements> {
std::array<detail::index_pair, total_num_elements> indices{};
[[maybe_unused]] auto p = indices.data();
((p = std::remove_cvref_t<Ts>::fill_inner_indices(p)), ...);
Expand Down Expand Up @@ -48,7 +49,8 @@ template <tuplelike... Ts> [[nodiscard]] constexpr auto tuple_cat(Ts &&...ts) {
constexpr auto total_num_elements =
(std::size_t{} + ... + stdx::tuple_size_v<std::remove_cvref_t<Ts>>);

[[maybe_unused]] constexpr auto element_indices = [&] {
[[maybe_unused]] constexpr auto element_indices =
[&]() -> std::array<detail::index_pair, total_num_elements> {
std::array<detail::index_pair, total_num_elements> indices{};
auto p = indices.data();
((p = std::remove_cvref_t<Ts>::fill_inner_indices(p)), ...);
Expand Down Expand Up @@ -112,7 +114,7 @@ template <template <typename T> typename Pred, tuplelike T>
(std::size_t{} + ... +
(Pred<stdx::tuple_element_t<Is, tuple_t>>::value ? std::size_t{1}
: std::size_t{}));
constexpr auto indices = [] {
constexpr auto indices = []() -> std::array<std::size_t, num_matches> {
auto a = std::array<std::size_t, num_matches>{};
[[maybe_unused]] auto it = a.begin();
[[maybe_unused]] auto copy_index =
Expand Down Expand Up @@ -286,7 +288,8 @@ struct chunk {

template <tuplelike T, template <typename> typename Proj = std::type_identity_t>
requires(tuple_size_v<T> > 1)
[[nodiscard]] constexpr auto create_chunks() {
[[nodiscard]] constexpr auto create_chunks()
-> std::array<chunk, count_chunks<T, Proj>()> {
auto index = std::size_t{};
std::array<chunk, count_chunks<T, Proj>()> chunks{};
++chunks[index].size;
Expand Down Expand Up @@ -410,11 +413,11 @@ template <template <typename> typename Proj = std::type_identity_t,
sorted_idxs[Is], sorted_idxs[Is + 1]>...};
}(std::make_index_sequence<stdx::tuple_size_v<tuple_t> - 1>{});

constexpr auto chunks = [&] {
constexpr auto chunk_count =
std::count(std::begin(tests), std::end(tests), false) + 1;
constexpr auto chunk_count =
std::count(std::begin(tests), std::end(tests), false) + 1;
constexpr auto chunks =
[&]() -> std::array<detail::chunk, chunk_count> {
std::array<detail::chunk, chunk_count> cs{};

auto index = std::size_t{};
++cs[index].size;
for (auto i = std::size_t{}; i < std::size(tests); ++i) {
Expand Down