Rerun C++ SDK
Loading...
Searching...
No Matches
type_traits.hpp
1#pragma once
2
3#include <iterator> // std::begin, std::end, std::size
4#include <type_traits>
5
6/// Type trait utilities.
7///
8/// The defined traits acts as an extension to std defined type traits and are used as utilities
9/// across the SDK.
10namespace rerun::traits {
11 /// Gets the value/element type of a container.
12 ///
13 /// This works for all types that stick with the std convention of having a `value_type` member type.
14 /// Fails to compile if the type does not have a `value_type` member type - this can be used for SFINAE checks.
15 template <typename T>
16 using value_type_of_t = typename std::remove_reference_t<T>::value_type;
17
18 /// \private
19 namespace details {
20 /// False type if a given type is not iterable and has a size (has `begin` and `end`).
21 template <typename T, typename = void>
22 struct is_iterable : std::false_type {};
23
24 /// True type if a given type is iterable and has a size (has `begin` and `end` implemented).
25 ///
26 /// Makes no restrictions on the type returned by `begin`/`end`.
27 template <typename T>
29 T, std::void_t<
30 decltype(std::begin(std::declval<T&>())), //
31 decltype(std::end(std::declval<T&>())) //
32 >> : std::true_type {};
33 } // namespace details
34
35 /// True if a given type is iterable, meaning there is a `begin` & `end` implementation.
36 ///
37 /// Makes no restrictions on the type returned by `begin`/`end`.
38 template <typename T>
40} // namespace rerun::traits
Type trait utilities.
Definition type_traits.hpp:10
typename std::remove_reference_t< T >::value_type value_type_of_t
Gets the value/element type of a container.
Definition type_traits.hpp:16
constexpr bool is_iterable_v
True if a given type is iterable, meaning there is a begin & end implementation.
Definition type_traits.hpp:39
False type if a given type is not iterable and has a size (has begin and end).
Definition type_traits.hpp:22