-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use canonical dimension order in blades
Change-Id: Id8730a7b484435b72188eaa479b443c795a55121
- Loading branch information
Showing
5 changed files
with
208 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#pragma once | ||
|
||
#include <algorithm> | ||
#include <cstddef> | ||
#include <type_traits> | ||
#include <utility> | ||
|
||
namespace geometry::detail { | ||
|
||
template <class InSeq, class OutSeq = std::index_sequence<>> | ||
struct sort_swap_first | ||
{ | ||
using type = OutSeq; | ||
}; | ||
template <std::size_t I0, std::size_t... Js> | ||
struct sort_swap_first<std::index_sequence<I0>, std::index_sequence<Js...>> | ||
{ | ||
using type = std::index_sequence<Js..., I0>; | ||
}; | ||
template <std::size_t I0, std::size_t I1, std::size_t... Is, std::size_t... Js> | ||
struct sort_swap_first< | ||
std::index_sequence<I0, I1, Is...>, | ||
std::index_sequence<Js...>> | ||
: std::conditional_t< | ||
(I0 > I1), | ||
sort_swap_first<std::index_sequence<>, | ||
std::index_sequence<Js..., I1, I0, Is...>>, | ||
sort_swap_first<std::index_sequence<I1, Is...>, | ||
std::index_sequence<Js..., I0>>> | ||
{}; | ||
|
||
template <class Seq> | ||
using sort_swap_first_t = typename sort_swap_first<Seq>::type; | ||
|
||
template <class Seq, std::size_t Swaps = 0, class = void> | ||
struct sort_swap : sort_swap<sort_swap_first_t<Seq>, Swaps + 1> | ||
{}; | ||
template <std::size_t... Is, std::size_t Swaps> | ||
struct sort_swap< | ||
std::index_sequence<Is...>, | ||
Swaps, | ||
std::enable_if_t<std::is_same_v< | ||
std::index_sequence<Is...>, | ||
sort_swap_first_t<std::index_sequence<Is...>>>>> | ||
{ | ||
using type = std::index_sequence<Is...>; | ||
static constexpr auto swap_count = Swaps; | ||
}; | ||
|
||
template <class Seq> | ||
struct sort_dimensions | ||
{ | ||
using type = typename sort_swap<Seq>::type; | ||
}; | ||
|
||
template <class Seq> | ||
using sort_dimensions_t = typename sort_dimensions<Seq>::type; | ||
|
||
template <class Seq> | ||
struct sort_dimensions_swap_count | ||
: std::integral_constant<std::size_t, sort_swap<Seq>::swap_count> | ||
{}; | ||
|
||
template <class Seq> | ||
inline constexpr auto sort_dimensions_swap_count_v = | ||
sort_dimensions_swap_count<Seq>::value; | ||
|
||
} // namespace geometry::detail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
|
||
#include <array> | ||
#include <cstddef> | ||
#include <utility> | ||
|
||
namespace geometry::detail { | ||
|
||
inline constexpr class | ||
{ | ||
template <class T> | ||
static constexpr auto impl(std::index_sequence<>, const std::array<T, 1>&) | ||
{ | ||
return true; | ||
} | ||
template < | ||
std::size_t... Is, | ||
class T, | ||
class = std::enable_if_t<(sizeof...(Is) != 0)>> | ||
static constexpr auto | ||
impl(std::index_sequence<Is...>, | ||
const std::array<T, sizeof...(Is) + 1>& values) | ||
{ | ||
return ((std::get<Is>(values) < std::get<Is + 1>(values)) and ...); | ||
} | ||
|
||
public: | ||
// 0-args | ||
constexpr auto operator()() const { return true; } | ||
// 1+-args | ||
template <class... Ts> | ||
constexpr auto operator()(std::size_t t0, Ts... ts) const | ||
{ | ||
static_assert((std::is_same_v<std::size_t, Ts> and ...)); | ||
return impl(std::index_sequence_for<Ts...>{}, std::array{t0, ts...}); | ||
} | ||
} unique_sorted{}; | ||
|
||
} // namespace geometry::detail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters