autoppl
v0.8
A C++ template library for probabilistic programming
|
#include <type_traits>
Go to the source code of this file.
Classes | |
struct | ppl::util::invalid_tag |
Namespaces | |
ppl | |
ppl::util | |
Macros | |
#define | DEFINE_HAS_TYPE(name) |
#define | DEFINE_HAS_FUNC(name) |
Functions | |
ppl::util::DEFINE_HAS_TYPE (value_t) | |
ppl::util::DEFINE_HAS_TYPE (pointer_t) | |
ppl::util::DEFINE_HAS_TYPE (const_pointer_t) | |
ppl::util::DEFINE_HAS_TYPE (id_t) | |
ppl::util::DEFINE_HAS_TYPE (index_t) | |
ppl::util::DEFINE_HAS_TYPE (vec_t) | |
ppl::util::DEFINE_HAS_TYPE (mat_t) | |
ppl::util::DEFINE_HAS_TYPE (shape_t) | |
ppl::util::DEFINE_HAS_TYPE (dist_value_t) | |
ppl::util::DEFINE_HAS_FUNC (size) | |
ppl::util::DEFINE_HAS_FUNC (id) | |
ppl::util::DEFINE_HAS_FUNC (get_variable) | |
ppl::util::DEFINE_HAS_FUNC (get_distribution) | |
#define DEFINE_HAS_FUNC | ( | name | ) |
Metaprogramming tool to check if name is a (public) member function of a given type T. All instances of this macro must be placed in this file for ease of maintenance. Macro definition is undefined at the end of the file.
has_func_name_v simply checks if type T has the public, non-overloaded member function "name". It always returns either true or false with no compiler-error, so long as T is resolved to a valid type.
assert_has_func_name_v asserts that type T has the public, non-overloaded member function "name". If "name" is not such function, it is a compiler error and an appropriate message is printed.
Ex. with "name" as "pdf"
namespace details { \ template<class T> \ struct has_func_pdf \ { \ private: \ template<typename V> static void impl(decltype(&V::pdf)); \ template<typename V> static bool impl(...); \ public: \ static constexpr bool value = std::is_same<void, decltype(impl<T>(0))>::value; \ }; \ \ template <bool b> \ struct assert_has_func_pdf \ { \ static_assert(b, \ "Type does not have public, non-overloaded " \ "member function ""pdf" \ ); \ }; \ \ template<> \ struct assert_has_func_pdf<true> : std::true_type \ {}; \ } \ template <class T> \ inline constexpr bool has_func_pdf_v = \ details::has_func_pdf<T>::value; \ template <class T> \ inline constexpr bool assert_has_func_pdf_v = \ details::assert_has_func_pdf<has_func_pdf_v<T>>::value; \
#define DEFINE_HAS_TYPE | ( | name | ) |
Metaprogramming tools to check if name is a (public) member alias of a given type T. All instances of this macro must be placed in this file for ease of maintenance. Macro definition is undefined at the end of the file.
has_type_name_v simply checks if type T has the member alias "name". It always returns either true or false with no compiler-error, so long as T is resolved to a valid type.
get_type_name_t returns T::name if "name" is a member alias of T, and otherwise returns type invalid_tag.
assert_has_type_name_v asserts that type T has the member alias "name". If "name" is not a member alias, it is a compiler error and an appropriate message is printed.
Ex. with "name" as "value_t"
namespace details { \ template<class T> \ struct has_type_value_t \ { \ private: \ template<typename V> static void impl(typename V::value_t*); \ template<typename V> static bool impl(...); \ public: \ static constexpr bool value = std::is_same<void, decltype(impl<T>(0))>::value; \ }; \ \ template <class T, bool = false> \ struct get_type_value_t \ { \ using type = invalid_tag; \ }; \ template <class T> \ struct get_type_value_t<T, true> \ { \ using type = typename T::value_t; \ }; \ \ template <bool b> \ struct assert_has_type_value_t \ { \ static_assert(b, "Type does not have member type ""value_t"); \ }; \ \ template<> \ struct assert_has_type_value_t<true> : std::true_type \ {}; \ } \ template <class T> \ inline constexpr bool has_type_value_t_v = \ details::has_type_value_t<T>::value; \ template <class T> \ inline constexpr bool assert_has_type_value_t_v = \ details::assert_has_type_value_t<has_type_value_t_v<T>>::value; \ template <class T> \ using get_type_value_t_t = \ typename details::get_type_value_t<T, has_type_value_t_v<T>>::type;