Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DPL: use constraints directly on arguments in place of requires #13767

Merged
merged 5 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 3 additions & 8 deletions Framework/Foundation/include/Framework/Endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,19 @@
#define O2_BIG_ENDIAN __BIG_ENDIAN
#define O2_LITTLE_ENDIAN __LITTLE_ENDIAN


template <typename T>
requires std::same_as<T, uint16_t>
inline uint16_t doSwap(uint16_t x)
inline uint16_t doSwap(std::same_as<uint16_t> auto x)
{
return swap16_(x);
}

template <typename T>
ktf marked this conversation as resolved.
Show resolved Hide resolved
requires std::same_as<T, uint32_t>
inline uint32_t doSwap(uint32_t x)
inline uint32_t doSwap(std::same_as<uint32_t> auto x)
{
return swap32_(x);
}

template <typename T>
ktf marked this conversation as resolved.
Show resolved Hide resolved
requires std::same_as<T, uint64_t>
inline uint64_t doSwap(uint64_t x)
inline uint64_t doSwap(std::same_as<uint64_t> auto x)
{
return swap64_(x);
}
Expand Down
23 changes: 12 additions & 11 deletions Framework/Foundation/include/Framework/Pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,42 +114,43 @@ consteval auto prune_voids_pack(Result result, pack<>)
return result;
}

template <typename T>
concept void_pack_element = std::is_void_v<T>;

template <typename T>
concept nonvoid_pack_element = !void_pack_element<T>;

// The first one is non void, but one of the others is void
template <typename... Rs, typename T, typename... Ts>
requires(!std::is_void_v<T>)
template <typename... Rs, nonvoid_pack_element T, typename... Ts>
consteval auto prune_voids_pack(pack<Rs...> result, pack<T, Ts...>)
{
return prune_voids_pack(pack<Rs..., T>{}, pack<Ts...>{});
}

// The first one is void
template <typename... Rs, typename V, typename... Ts>
requires(std::is_void_v<V>)
template <typename... Rs, void_pack_element V, typename... Ts>
consteval auto prune_voids_pack(pack<Rs...> result, pack<V, Ts...>)
{
return prune_voids_pack(pack<Rs...>{}, pack<Ts...>{});
}

// The first one is non void, but one of the others is void
template <typename... Rs, typename T1, typename T2, typename... Ts>
requires(!std::is_void_v<T1> && !std::is_void_v<T2>)
template <typename... Rs, nonvoid_pack_element T1, nonvoid_pack_element T2, typename... Ts>
consteval auto prune_voids_pack(pack<Rs...> result, pack<T1, T2, Ts...>)
{
return prune_voids_pack(pack<Rs..., T1, T2>{}, pack<Ts...>{});
}

// Eats 4 types at the time
template <typename... Rs, typename T1, typename T2, typename T3, typename T4, typename... Ts>
requires(!std::is_void_v<T1> && !std::is_void_v<T2> && !std::is_void_v<T3> && !std::is_void_v<T4>)
template <typename... Rs, nonvoid_pack_element T1, nonvoid_pack_element T2, nonvoid_pack_element T3, nonvoid_pack_element T4, typename... Ts>
consteval auto prune_voids_pack(pack<Rs...> result, pack<T1, T2, T3, T4, Ts...>)
{
return prune_voids_pack(pack<Rs..., T1, T2, T3, T4>{}, pack<Ts...>{});
}

// Eats 8 types at the time
template <typename... Rs, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8, typename... Ts>
requires(!std::is_void_v<T1> && !std::is_void_v<T2> && !std::is_void_v<T3> && !std::is_void_v<T4> && !std::is_void_v<T5> && !std::is_void_v<T6> && !std::is_void_v<T7> && !std::is_void_v<T8>)
template <typename... Rs, nonvoid_pack_element T1, nonvoid_pack_element T2, nonvoid_pack_element T3, nonvoid_pack_element T4,
nonvoid_pack_element T5, nonvoid_pack_element T6, nonvoid_pack_element T7, nonvoid_pack_element T8, typename... Ts>
consteval auto prune_voids_pack(pack<Rs...> result, pack<T1, T2, T3, T4, T5, T6, T7, T8, Ts...>)
{
return prune_voids_pack(pack<Rs..., T1, T2, T3, T4, T5, T6, T7, T8>{}, pack<Ts...>{});
Expand Down
Loading