OpenKalman
size_of.hpp
Go to the documentation of this file.
1 /* This file is part of OpenKalman, a header-only C++ library for
2  * Kalman filters and other recursive filters.
3  *
4  * Copyright (c) 2024-2026 Christopher Lee Ogden <ogden@gatech.edu>
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
9  */
10 
16 #ifndef OPENKALMAN_COLLECTIONS_SIZE_OF_HPP
17 #define OPENKALMAN_COLLECTIONS_SIZE_OF_HPP
18 
19 #include "values/values.hpp"
22 
24 {
28 #ifdef __cpp_concepts
29  template<typename T>
30 #else
31  template<typename T, typename = void>
32 #endif
33  struct size_of {};
34 
35 
36 #ifdef __cpp_concepts
37  template<sized T> requires (not values::fixed<decltype(collections::get_size(std::declval<T>()))>)
38  struct size_of<T>
39 #else
40  template<typename T>
41  struct size_of<T, std::enable_if_t<
42  sized<T> and not values::fixed<decltype(collections::get_size(std::declval<T>()))>>>
43 #endif
44  : std::integral_constant<std::size_t, stdex::dynamic_extent> {};
45 
46 
47 #ifdef __cpp_concepts
48  template<sized T> requires values::fixed<decltype(collections::get_size(std::declval<T>()))>
49  struct size_of<T>
50 #else
51  template<typename T>
52  struct size_of<T, std::enable_if_t<
53  sized<T> and values::fixed<decltype(collections::get_size(std::declval<T>()))>>>
54 #endif
56 
57 
61  template<typename T>
62  inline constexpr std::size_t size_of_v = size_of<T>::value;
63 
64 
68  template<typename T>
69  using size_of_t = std::conditional_t<sized<T>, size_of<T>, values::unbounded_size_t>;
70 
71 }
72 
73 #endif
Namespace for collections.
Definition: collections.hpp:27
constexpr auto get_size(Arg &&arg)
Get the size of a sized object (e.g, a collection)
Definition: get_size.hpp:224
Header file for code relating to values (e.g., scalars and indices)
The size of a sized object (including a collection).
Definition: size_of.hpp:33
The fixed value associated with a fixed.
Definition: fixed_value_of.hpp:44
Definition for collections::sized.
Definition for collections::get_size.
std::conditional_t< sized< T >, size_of< T >, values::unbounded_size_t > size_of_t
The type of the argument&#39;s size, which will satisfy values::size.
Definition: size_of.hpp:69
A type reflecting an unbound size.
Definition: size.hpp:27
constexpr bool fixed
T has a value that is determinable at compile time.
Definition: fixed.hpp:65
constexpr std::size_t size_of_v
Helper for collections::size_of.
Definition: size_of.hpp:62