Browse Source

* improved meta programming code

master
bergmann 6 years ago
parent
commit
558dc92e75
2 changed files with 62 additions and 19 deletions
  1. +42
    -13
      src/cpputils/mp/core/checker.h
  2. +20
    -6
      src/cpputils/mp/core/const.h

+ 42
- 13
src/cpputils/mp/core/checker.h View File

@@ -14,6 +14,8 @@ namespace mp {
template<bool...>
struct bool_pack;

/* is_specialization_of */

template<typename T, template <typename...> class T_template>
struct is_specialization_of_impl
: c_false_t
@@ -23,46 +25,73 @@ namespace mp {
struct is_specialization_of_impl<T_template<Ts...>, T_template>
: c_true_t
{ };

}

template<typename T, typename S>
using is_same = c_bool_t<std::is_same<T, S>::value>;
struct is_same
: c_bool_t<std::is_same<T, S>::value>
{ };

template<typename Base, typename Derived>
using is_base_of = c_bool_t<std::is_base_of<Base, Derived>::value>;
struct is_base_of :
c_bool_t<std::is_base_of<Base, Derived>::value>
{ };

template<typename... T>
using is_constructible = c_bool_t<std::is_constructible<T...>::value>;
struct is_constructible :
c_bool_t<std::is_constructible<T...>::value>
{ };

template<typename... T>
using is_empty = c_bool_t<std::is_empty<T...>::value>;
struct is_empty :
c_bool_t<std::is_empty<T...>::value>
{ };

template<typename... T>
using is_final = c_bool_t<std::is_final<T...>::value>;
struct is_final :
c_bool_t<std::is_final<T...>::value>
{ };

template<typename T, typename U>
using is_convertible = c_bool_t<std::is_convertible<T, U>::value>;
struct is_convertible :
c_bool_t<std::is_convertible<T, U>::value>
{ };

template<typename T, typename U>
using is_assignable = c_bool_t<std::is_assignable<T, U>::value>;
struct is_assignable :
c_bool_t<std::is_assignable<T, U>::value>
{ };

template<typename... T>
using is_valid = __impl::is_valid_impl<T...>;
struct is_valid :
__impl::is_valid_impl<T...>
{ };

template<typename T>
using is_arithmetic = c_bool_t<std::is_arithmetic<T>::value>;
struct is_arithmetic :
c_bool_t<std::is_arithmetic<T>::value>
{ };

template<typename T>
using is_signed = c_bool_t<std::is_signed<T>::value>;
struct is_signed :
c_bool_t<std::is_signed<T>::value>
{ };

template<typename T>
using is_unsigned = c_bool_t<std::is_unsigned<T>::value>;
struct is_unsigned :
c_bool_t<std::is_unsigned<T>::value>
{ };

template<typename T, template <typename...> class T_template>
using is_specialization_of = __impl::is_specialization_of_impl<T, T_template>;
struct is_specialization_of :
__impl::is_specialization_of_impl<T, T_template>
{ };

template<bool... B>
using all_true = c_bool_t<std::is_same<__impl::bool_pack<true, B...>, __impl::bool_pack<B..., true>>::value>;
struct all_true :
c_bool_t<std::is_same<__impl::bool_pack<true, B...>, __impl::bool_pack<B..., true>>::value>
{ };

namespace __impl /* implementation */
{


+ 20
- 6
src/cpputils/mp/core/const.h View File

@@ -7,17 +7,31 @@ namespace utl {
namespace mp {

template<typename T, T t>
using integral_constant = std::integral_constant<T, t>;
struct integral_constant
: std::integral_constant<T, t>
{ };

template<bool B>
using c_bool_t = integral_constant<bool, B>;
struct c_bool_t
: integral_constant<bool, B>
{ };

template<size_t S>
using c_size_t = integral_constant<size_t, S>;
struct c_size_t
: integral_constant<size_t, S>
{ };

using c_zero_t = c_size_t<0>;
using c_true_t = c_bool_t<true>;
using c_false_t = c_bool_t<false>;
struct c_zero_t
: c_size_t<0>
{ };

struct c_true_t
: c_bool_t<true>
{ };

struct c_false_t
: c_bool_t<false>
{ };

template<size_t S>
constexpr c_size_t<S> c_size { };


Loading…
Cancel
Save