autoppl  v0.8
A C++ template library for probabilistic programming
concept.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <type_traits>
3 
66 #define DEFINE_HAS_TYPE(name) \
67  namespace details { \
68  template<class T> \
69  struct has_type_##name \
70  { \
71  private: \
72  template<typename V> static void impl(typename V::name*); \
73  template<typename V> static bool impl(...); \
74  public: \
75  static constexpr bool value = std::is_same<void, decltype(impl<T>(0))>::value; \
76  }; \
77  \
78  template <class T, bool = false> \
79  struct get_type_##name \
80  { \
81  using type = invalid_tag; \
82  }; \
83  template <class T> \
84  struct get_type_##name<T, true> \
85  { \
86  using type = typename T::name; \
87  }; \
88  \
89  template <bool b> \
90  struct assert_has_type_##name \
91  { \
92  static_assert(b, "Type does not have member type "#name); \
93  }; \
94  \
95  template<> \
96  struct assert_has_type_##name<true> : std::true_type \
97  {}; \
98  } \
99  template <class T> \
100  inline constexpr bool has_type_##name##_v = \
101  details::has_type_##name<T>::value; \
102  template <class T> \
103  inline constexpr bool assert_has_type_##name##_v = \
104  details::assert_has_type_##name<has_type_##name##_v<T>>::value; \
105  template <class T> \
106  using get_type_##name##_t = \
107  typename details::get_type_##name<T, has_type_##name##_v<T>>::type;
108 
109 
159 #define DEFINE_HAS_FUNC(name) \
160  namespace details { \
161  template<class T> \
162  struct has_func_##name \
163  { \
164  private: \
165  template<typename V> static void impl(decltype(&V::name)); \
166  template<typename V> static bool impl(...); \
167  public: \
168  static constexpr bool value = std::is_same<void, decltype(impl<T>(0))>::value; \
169  }; \
170  \
171  template <bool b> \
172  struct assert_has_func_##name \
173  { \
174  static_assert(b, \
175  "Type does not have public, non-overloaded " \
176  "member function "#name \
177  ); \
178  }; \
179  \
180  template<> \
181  struct assert_has_func_##name<true> : std::true_type \
182  {}; \
183  } \
184  template <class T> \
185  inline constexpr bool has_func_##name##_v = \
186  details::has_func_##name<T>::value; \
187  template <class T> \
188  inline constexpr bool assert_has_func_##name##_v = \
189  details::assert_has_func_##name<has_func_##name##_v<T>>::value; \
190 
191 namespace ppl {
192 namespace util {
193 
199 {
200  invalid_tag() =delete;
201  ~invalid_tag() =delete;
202  invalid_tag(const invalid_tag&) =delete;
206 };
207 
209 DEFINE_HAS_TYPE(pointer_t);
210 DEFINE_HAS_TYPE(const_pointer_t);
217 
220 
221 DEFINE_HAS_FUNC(get_variable);
222 DEFINE_HAS_FUNC(get_distribution);
223 
224 } // namespace util
225 } // namespace ppl
226 
227 #undef DEFINE_HAS_FUNC
228 #undef DEFINE_HAS_TYPE
ppl::util::invalid_tag::invalid_tag
invalid_tag(invalid_tag &&)=delete
ppl::util::invalid_tag::operator=
invalid_tag & operator=(const invalid_tag &)=delete
ppl::util::invalid_tag::~invalid_tag
~invalid_tag()=delete
ppl::util::invalid_tag::operator=
invalid_tag & operator=(invalid_tag &&)=delete
ppl::util::invalid_tag::invalid_tag
invalid_tag(const invalid_tag &)=delete
ppl::util::DEFINE_HAS_FUNC
DEFINE_HAS_FUNC(size)
ppl::util::size
constexpr size_t size(const T &x)
Definition: value.hpp:22
ppl::util::dist_value_t
double dist_value_t
Definition: dist_expr_traits.hpp:13
ppl
Definition: bounded.hpp:11
ppl::util::DEFINE_HAS_TYPE
DEFINE_HAS_TYPE(value_t)
ppl::util::invalid_tag::invalid_tag
invalid_tag()=delete
ppl::util::invalid_tag
Definition: concept.hpp:199