Rerun C++ SDK
Loading...
Searching...
No Matches
loggable.hpp
1#pragma once
2
3#include <type_traits> // std::false_type
4
5namespace rerun {
6 /// The Loggable trait is used by all built-in implementation of `rerun::AsComponents`
7 /// to serialize a collection for logging.
8 ///
9 /// It is implemented for all built-in `rerun::component`s and `rerun::datatype`s.
10 template <typename T>
11 struct Loggable {
12 /// \private
13 /// `NoLoggableFor` always evaluates to false, but in a way that requires template instantiation.
14 template <typename T2>
15 struct NoLoggableFor : std::false_type {};
16
17 static_assert(
18 NoLoggableFor<T>::value,
19 "Loggable is not implemented for this type. "
20 "It is implemented for all built-in datatypes and components. "
21 "To check ahead of template instantiation whether a type is loggable, use `is_loggable<T>`"
22 );
23
24 // TODO(andreas): List methods that the trait should implement.
25 };
26
27 /// \private
28 namespace detail {
29 /// Helper to check whether a type implements the Loggable trait.
30 ///
31 /// Uses SFINAE to ensure that a given type T *specializes* the `rerun::Loggable` trait.
32 /// The non-specialized `Loggable<T>` is the only implementation which contains `NoLoggableFor<T>`,
33 /// so if that type exists we know the type does not specialize the `Loggable` trait.
34 template <typename T>
35 constexpr auto is_loggable(int = 0) ->
36 typename Loggable<T>::template NoLoggableFor<T>::value_type {
37 return false;
38 }
39
40 /// Helper to check whether a type implements the Loggable trait.
41 ///
42 /// Uses SFINAE to ensure that a given type T *specializes* the `rerun::Loggable` trait.
43 /// The non-specialized `Loggable<T>` is the only implementation which contains `NoLoggableFor<T>`,
44 /// so if that type exists we know the type does not specialize the `Loggable` trait.
45 template <typename T>
46 constexpr bool is_loggable(...) {
47 return true;
48 }
49 } // namespace detail
50
51 /// True for any type that implements the Loggable trait.
52 template <typename T>
53 constexpr bool is_loggable = detail::is_loggable<T>();
54} // namespace rerun
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:20
constexpr bool is_loggable
True for any type that implements the Loggable trait.
Definition loggable.hpp:53
The Loggable trait is used by all built-in implementation of rerun::AsComponents to serialize a colle...
Definition loggable.hpp:11