ソースを参照

* added mp::when, mp::array_properties, mp::is_specialization_of

master
bergmann 6年前
コミット
cc0b38171c
6個のファイルの変更79行の追加13行の削除
  1. +1
    -12
      src/cpputils/misc/linq.h
  2. +3
    -1
      src/cpputils/mp/core.h
  3. +29
    -0
      src/cpputils/mp/core/array.h
  4. +19
    -0
      src/cpputils/mp/core/checker.h
  5. +20
    -0
      src/cpputils/mp/core/when.h
  6. +7
    -0
      test/mp/core.cpp

+ 1
- 12
src/cpputils/misc/linq.h ファイルの表示

@@ -50,17 +50,6 @@ namespace linq {
struct tag_builder { };

/* meta programming **********************************************************************/
template<class TArray>
struct mp_array_properties;

template<class T, size_t N>
struct mp_array_properties<T[N]>
{
using size = std::integral_constant<size_t, N>;
using value_type = T;
using iterator_type = T*;
};

template<class T>
using mp_range_value_type = typename utl::mp::remove_ref<T>::value_type;

@@ -1510,7 +1499,7 @@ namespace linq {
inline auto from_array(TArray&& array)
{
using array_type = typename std::remove_reference<TArray>::type;
using array_size = typename __impl::mp_array_properties<array_type>::size;
using array_size = typename utl::mp::array_properties<array_type>::size;
return from_iterator(&array[0], &array[array_size::value]);
}



+ 3
- 1
src/cpputils/mp/core.h ファイルの表示

@@ -1,7 +1,9 @@
#pragma once

#include <cpputils/mp/core/array.h>
#include <cpputils/mp/core/checker.h>
#include <cpputils/mp/core/conditionals.h>
#include <cpputils/mp/core/const.h>
#include <cpputils/mp/core/modifier.h>
#include <cpputils/mp/core/types.h>
#include <cpputils/mp/core/types.h>
#include <cpputils/mp/core/when.h>

+ 29
- 0
src/cpputils/mp/core/array.h ファイルの表示

@@ -0,0 +1,29 @@
#pragma once

#include <cstddef>
#include <cpputils/mp/core/const.h>

namespace utl {
namespace mp {

template<class TArray>
struct array_properties;

template<class T, size_t N>
struct array_properties<T[N]>
{
using size = c_size_t<N>;
using value_type = T;
using iterator_type = T*;
};

template<class T, size_t N>
struct array_properties<T(&)[N]>
{
using size = c_size_t<N>;
using value_type = T;
using iterator_type = T*;
};

}
}

+ 19
- 0
src/cpputils/mp/core/checker.h ファイルの表示

@@ -10,6 +10,19 @@ namespace mp {
{
template<typename...>
struct is_valid_impl;

template<bool...>
struct bool_pack;

template<typename T, template <typename...> class T_template>
struct is_specialization_of_impl
: c_false_t
{ };

template<template <typename...> class T_template, typename... Ts>
struct is_specialization_of_impl<T_template<Ts...>, T_template>
: c_true_t
{ };
}

template<typename T, typename S>
@@ -45,6 +58,12 @@ namespace mp {
template<typename T>
using 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>;

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

namespace __impl /* implementation */
{
template<typename...>


+ 20
- 0
src/cpputils/mp/core/when.h ファイルの表示

@@ -0,0 +1,20 @@
#pragma once

namespace utl {
namespace mp {

namespace __impl
{
template <typename ...>
struct always_true
{ static constexpr bool value = true; };
}

template <bool condition>
struct when;

template <typename... T>
using when_valid = when<__impl::always_true<T...>::value>;

}
}

+ 7
- 0
test/mp/core.cpp ファイルの表示

@@ -21,3 +21,10 @@ static_assert(std::is_same<eval_if_expected_0, eval_if_actual_0>::value, "eval_i
using eval_if_expected_1 = int*;
using eval_if_actual_1 = eval_if_c<false, int, add_pointer, int>;
static_assert(std::is_same<eval_if_expected_1, eval_if_actual_1>::value, "");

/* is_specializatzion_of */
template<class T, class U>
struct my_template { };
using spec_template = my_template<int, double>;
static_assert(is_specialization_of<spec_template, my_template>::value, "");
static_assert(!is_specialization_of<int, my_template>::value, "");

読み込み中…
キャンセル
保存