autoppl  v0.8
A C++ template library for probabilistic programming
type_traits.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <cstddef>
3 #include <type_traits>
4 
5 #define DEFINE_ASSERT_ONE_PARAM(name) \
6  namespace details { \
7  template <bool b> \
8  struct assert_##name \
9  { \
10  static_assert(b, \
11  "Assert "#name" failed" \
12  ); \
13  }; \
14  \
15  template<> \
16  struct assert_##name<true> : std::true_type \
17  {}; \
18  } \
19  template <class T> \
20  inline constexpr bool assert_##name = \
21  details::assert_##name<name<T>>::value; \
22 
23 #define DEFINE_ASSERT_TWO_PARAM(name) \
24  namespace details { \
25  template <bool b> \
26  struct assert_##name \
27  { \
28  static_assert(b, \
29  "Assert "#name" failed" \
30  ); \
31  }; \
32  \
33  template<> \
34  struct assert_##name<true> : std::true_type \
35  {}; \
36  } \
37  template <class T, class U> \
38  inline constexpr bool assert_##name = \
39  details::assert_##name<name<T, U>>::value; \
40 
41 // Important type checking error messages
42 #define PPL_CONT_XOR_DISC \
43  "Expression must be either continuous or discrete. " \
44  "It cannot be both continuous and discrete. "
45 
46 namespace ppl {
47 namespace util {
48 
52 template <class From, class To>
53 inline constexpr bool is_explicitly_convertible_v =
54  std::is_constructible_v<To, From> &&
55  !std::is_convertible_v<From, To>
56  ;
58 
63 template <class T>
64 struct BaseCRTP
65 {
66  T& self() { return static_cast<T&>(*this); }
67  const T& self() const { return static_cast<const T&>(*this); }
68 };
69 
70 template <class T>
71 inline constexpr bool is_cont_v = std::is_floating_point_v<T>;
72 
73 template <class T>
74 inline constexpr bool is_disc_v = std::is_integral_v<T>;
75 
76 } // namespace util
77 } // namespace ppl
ppl::util::is_cont_v
constexpr bool is_cont_v
Definition: type_traits.hpp:71
ppl::util::is_disc_v
constexpr bool is_disc_v
Definition: type_traits.hpp:74
ppl::util::BaseCRTP
Definition: type_traits.hpp:65
ppl::util::DEFINE_ASSERT_TWO_PARAM
DEFINE_ASSERT_TWO_PARAM(is_explicitly_convertible_v)
ppl::util::is_explicitly_convertible_v
constexpr bool is_explicitly_convertible_v
Definition: type_traits.hpp:53
ppl
Definition: bounded.hpp:11