-
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.
add
detail::indices_{of,array}
to obtain indices of a mask
Change-Id: Id94ba16a00352a56bca915b0793b31bb08412bef
- Loading branch information
Showing
9 changed files
with
159 additions
and
58 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
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,25 @@ | ||
#pragma once | ||
|
||
#include "rigid_geometric_algebra/detail/contract.hpp" | ||
#include "rigid_geometric_algebra/detail/indices_of.hpp" | ||
|
||
#include <algorithm> | ||
#include <array> | ||
#include <cstddef> | ||
#include <functional> | ||
|
||
namespace rigid_geometric_algebra::detail { | ||
|
||
/// create an array containing the indices of a mask | ||
/// | ||
template <auto mask, auto pred = std::identity{}> | ||
inline constexpr auto indices_array = [] { | ||
auto indices = std::array<std::size_t, std::ranges::count_if(mask, pred)>{}; | ||
|
||
auto it = detail::indices_of(mask, indices.begin()); | ||
detail::postcondition(it == indices.end()); | ||
|
||
return indices; | ||
}(); | ||
|
||
} // namespace rigid_geometric_algebra::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,38 @@ | ||
#pragma once | ||
|
||
#include <concepts> | ||
#include <cstddef> | ||
#include <functional> | ||
#include <iterator> | ||
#include <ranges> | ||
|
||
namespace rigid_geometric_algebra::detail { | ||
|
||
/// determine indices of a range that satisfy a unary predicate | ||
/// | ||
inline constexpr class | ||
{ | ||
public: | ||
template < | ||
std::ranges::forward_range R, | ||
std::weakly_incrementable O, | ||
class UnaryPredicate = std::identity> | ||
requires std::unsigned_integral<std::iter_value_t<O>> and | ||
std::indirect_unary_predicate< | ||
UnaryPredicate, | ||
std::ranges::iterator_t<R>> | ||
static constexpr auto | ||
operator()(R&& rng, O dest, UnaryPredicate pred = {}) -> O | ||
{ | ||
for (auto index = std::iter_value_t<O>{}; | ||
const auto& element : std::forward<R>(rng)) { | ||
if (pred(element)) { | ||
*dest++ = index; | ||
} | ||
++index; | ||
} | ||
return dest; | ||
} | ||
} indices_of{}; | ||
|
||
} // namespace rigid_geometric_algebra::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
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