Skip to content

Commit d650687

Browse files
[filter] add internal deducer Eigen3 concept support (#313)
1 parent babad2e commit d650687

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

include/fcarouge/internal/utility.hpp

+13-14
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ concept arithmetic = std::integral<Type> || std::floating_point<Type>;
5050
template <typename Type>
5151
concept algebraic = not arithmetic<Type>;
5252

53+
template <typename Type>
54+
concept eigen = requires {
55+
typename Type::PlainMatrix;
56+
};
57+
5358
struct empty {
5459
inline constexpr explicit empty([[maybe_unused]] auto &&...any) noexcept {
5560
// Constructs from anything for all initializations compatibility.
@@ -122,36 +127,30 @@ struct transpose final {
122127
//! correctly sized resulting matrix but the correctness of the units have yet
123128
//! to be proven, nor whether its systematic usage is in fact appropriate.
124129
//! Hypothesis: units are incorrect, usage may be incorrect, for example
125-
//! `state_transition` may actually be unit-less. Note the lhs column size and
126-
//! rhs row size are the resulting type's column and row sizes, respectively:
130+
//! `state_transition` may actually be unit-less. Note the `lhs` column size and
131+
//! `rhs` row size are the resulting type's column and row sizes, respectively:
127132
//! Lhs [m by n] and Rhs [o by n] -> Result [m by o].
128133
//! @todo Is there a better, simpler, canonical, standard way of doing this type
129-
//! deductions?
134+
//! deduction?
130135
struct deducer final {
131-
// Built-in's types deductions.
136+
// Built-in, arithmetic, standard division support.
132137
template <arithmetic Lhs, arithmetic Rhs>
133138
[[nodiscard]] inline constexpr auto operator()(const Lhs &lhs,
134139
const Rhs &rhs) const
135140
-> decltype(lhs / rhs);
136141

137-
// Eigen's types deductions.
138-
template <typename Lhs, typename Rhs>
139-
requires requires(Lhs lhs, Rhs rhs) {
140-
typename Lhs::PlainMatrix;
141-
typename Lhs::PlainMatrix;
142-
}
142+
// Type-erased Eigen third party linear algebra support.
143+
template <eigen Lhs, eigen Rhs>
143144
[[nodiscard]] inline constexpr auto operator()(const Lhs &lhs,
144145
const Rhs &rhs) const ->
145146
typename decltype(lhs * rhs.transpose())::PlainMatrix;
146147

147-
template <typename Lhs, arithmetic Rhs>
148-
requires requires(Lhs lhs) { typename Lhs::PlainMatrix; }
148+
template <eigen Lhs, arithmetic Rhs>
149149
[[nodiscard]] inline constexpr auto operator()(const Lhs &lhs,
150150
const Rhs &rhs) const ->
151151
typename Lhs::PlainMatrix;
152152

153-
template <arithmetic Lhs, typename Rhs>
154-
requires requires(Rhs rhs) { typename Rhs::PlainMatrix; }
153+
template <arithmetic Lhs, eigen Rhs>
155154
[[nodiscard]] inline constexpr auto operator()(const Lhs &lhs,
156155
const Rhs &rhs) const ->
157156
typename decltype(rhs.transpose())::PlainMatrix;

0 commit comments

Comments
 (0)