dot-xx
A personal collection of small C++ modules
Loading...
Searching...
No Matches
dxx::math::container_traits::autodetect Namespace Reference

Auto-detection of container traits. More...

Variables

template<vector V>
constexpr auto size
template<typename T, uz t_size>
constexpr auto size< std::span< T, t_size > > = size::Static{ .size = t_size }
template<typename T>
constexpr auto size< std::span< T, std::dynamic_extent > > = size::RuntimeFixed{}

Detailed Description

Auto-detection of container traits.

Variable Documentation

◆ size

template<vector V>
auto dxx::math::container_traits::autodetect::size
constexpr
Initial value:
= [] {
using namespace size;
constexpr bool has_tuple_size = requires {
{ std::tuple_size<V>::value } -> std::same_as<const uz&>;
}; // <-- has_tuple_size
constexpr bool has_max_size = requires {
{ V::max_size() } -> std::same_as<uz>;
}; // <-- has_max_size
if constexpr (requires (V v, uz sz) { { v.resize(sz) }; }) {
// The container is resizeable
if constexpr (has_max_size) {
return Bound{ .max_size = V::max_size };
} else {
return Dynamic{};
}
} else {
if constexpr (has_tuple_size) {
return Static{ .size = std::tuple_size_v<V> };
} else if constexpr (has_max_size) {
return Static{ .size = V::max_size };
} else {
// Treat everything else as something that we don't know how to
// resize and don't know a compile-time size of
return RuntimeFixed{};
}
}
} ()