16 #ifndef OPENKALMAN_IS_SQUARE_SHAPED_HPP 17 #define OPENKALMAN_IS_SQUARE_SHAPED_HPP 20 #include "coordinates/coordinates.hpp" 30 template<
typename T, std::
size_t i>
32 get_best_square_index()
34 if constexpr (i == 0) return i;
36 else return get_best_square_index<T, i - 1>();
40 template<typename T,
std::
size_t...is>
42 is_square_shaped_impl(const T& t,
std::index_sequence<is...>)
44 constexpr std::size_t best = get_best_square_index<T,
sizeof...(is)>();
45 auto best_patt = get_index_pattern<best>(t);
46 using opt = std::optional<std::decay_t<decltype(best_patt)>>;
47 if ((... and (is == best or
coordinates::compare(get_index_pattern<is>(t), best_patt))))
return opt {best_patt};
66 template<
typename T, std::enable_if_t<indexible<T>,
int> = 0>
71 if constexpr (index_count_v<T> == stdex::dynamic_extent)
73 auto d0 = get_index_pattern<0>(t);
77 return std::optional<decltype((d0))> {};
79 return std::optional {d0};
83 constexpr std::size_t c = index_count_v<T>;
86 using opt = std::optional<coordinates::Dimensions<1>>;
92 return detail::is_square_shaped_impl(t, std::make_index_sequence<c>{});
constexpr auto compare(const A &a, const B &b)
Compare two coordinates::pattern objects lexicographically.
Definition: compare.hpp:40
constexpr auto count_indices(const T &)
Get the number of indices necessary to address all the components of an indexible object...
Definition: count_indices.hpp:51
constexpr auto is_square_shaped(const T &t)
Determine whether an object is square_shaped.
Definition: is_square_shaped.hpp:69
Definition of count_indices.
The root namespace for OpenKalman.
Definition: basics.hpp:34
constexpr bool fixed_pattern
A coordinates::pattern for which the dimension is fixed at compile time.
Definition: fixed_pattern.hpp:46
Definition for index_count.
Definition of get_index_pattern function.
A structure representing the dimensions associated with of a particular index.
Definition: Dimensions.hpp:42
decltype(auto) constexpr get_index_pattern(T &&t, I i={})
Get the coordinates::pattern associated with indexible object T at a given index. ...
Definition: get_index_pattern.hpp:41