use detail::enable_if_t everywhere

This commit is contained in:
Wenzel Jakob 2016-09-13 00:36:43 +09:00
parent 8e5dceb6a6
commit c1fc27e2b5
10 changed files with 63 additions and 63 deletions

View File

@ -276,7 +276,7 @@ template <> struct process_attribute<arg_v> : process_attribute_default<arg_v> {
/// Process a parent class attribute
template <typename T>
struct process_attribute<T, typename std::enable_if<std::is_base_of<handle, T>::value>::type> : process_attribute_default<handle> {
struct process_attribute<T, enable_if_t<std::is_base_of<handle, T>::value>> : process_attribute_default<handle> {
static void init(const handle &h, type_record *r) { r->bases.append(h); }
};
@ -298,13 +298,13 @@ struct process_attribute<multiple_inheritance> : process_attribute_default<multi
* otherwise
*/
template <int Nurse, int Patient> struct process_attribute<keep_alive<Nurse, Patient>> : public process_attribute_default<keep_alive<Nurse, Patient>> {
template <int N = Nurse, int P = Patient, typename std::enable_if<N != 0 && P != 0, int>::type = 0>
template <int N = Nurse, int P = Patient, enable_if_t<N != 0 && P != 0, int> = 0>
static void precall(handle args) { keep_alive_impl(Nurse, Patient, args, handle()); }
template <int N = Nurse, int P = Patient, typename std::enable_if<N != 0 && P != 0, int>::type = 0>
template <int N = Nurse, int P = Patient, enable_if_t<N != 0 && P != 0, int> = 0>
static void postcall(handle, handle) { }
template <int N = Nurse, int P = Patient, typename std::enable_if<N == 0 || P == 0, int>::type = 0>
template <int N = Nurse, int P = Patient, enable_if_t<N == 0 || P == 0, int> = 0>
static void precall(handle) { }
template <int N = Nurse, int P = Patient, typename std::enable_if<N == 0 || P == 0, int>::type = 0>
template <int N = Nurse, int P = Patient, enable_if_t<N == 0 || P == 0, int> = 0>
static void postcall(handle args, handle ret) { keep_alive_impl(Nurse, Patient, args, ret); }
};

View File

@ -343,10 +343,10 @@ protected:
#else
/* Visual Studio 2015's SFINAE implementation doesn't yet handle the above robustly in all situations.
Use a workaround that only tests for constructibility for now. */
template <typename T = type, typename = typename std::enable_if<std::is_copy_constructible<T>::value>::type>
template <typename T = type, typename = enable_if_t<std::is_copy_constructible<T>::value>>
static Constructor make_copy_constructor(const T *value) {
return [](const void *arg) -> void * { return new T(*((const T *)arg)); }; }
template <typename T = type, typename = typename std::enable_if<std::is_move_constructible<T>::value>::type>
template <typename T = type, typename = enable_if_t<std::is_move_constructible<T>::value>>
static Constructor make_move_constructor(const T *value) {
return [](const void *arg) -> void * { return (void *) new T(std::move(*((T *)arg))); }; }
#endif
@ -387,8 +387,8 @@ public:
template <typename T>
struct type_caster<
T, typename std::enable_if<std::is_integral<T>::value ||
std::is_floating_point<T>::value>::type> {
T, enable_if_t<std::is_integral<T>::value ||
std::is_floating_point<T>::value>> {
typedef typename std::conditional<sizeof(T) <= sizeof(long), long, long long>::type _py_type_0;
typedef typename std::conditional<std::is_signed<T>::value, _py_type_0, typename std::make_unsigned<_py_type_0>::type>::type _py_type_1;
typedef typename std::conditional<std::is_floating_point<T>::value, double, _py_type_1>::type py_type;
@ -702,20 +702,20 @@ public:
return load(src, convert, typename make_index_sequence<sizeof...(Tuple)>::type());
}
template <typename T = itype, typename std::enable_if<
template <typename T = itype, enable_if_t<
!std::is_same<T, args_type>::value &&
!std::is_same<T, args_kwargs_type>::value, int>::type = 0>
!std::is_same<T, args_kwargs_type>::value, int> = 0>
bool load_args(handle args, handle, bool convert) {
return load(args, convert, typename make_index_sequence<sizeof...(Tuple)>::type());
}
template <typename T = itype, typename std::enable_if<std::is_same<T, args_type>::value, int>::type = 0>
template <typename T = itype, enable_if_t<std::is_same<T, args_type>::value, int> = 0>
bool load_args(handle args, handle, bool convert) {
std::get<0>(value).load(args, convert);
return true;
}
template <typename T = itype, typename std::enable_if<std::is_same<T, args_kwargs_type>::value, int>::type = 0>
template <typename T = itype, enable_if_t<std::is_same<T, args_kwargs_type>::value, int> = 0>
bool load_args(handle args, handle kwargs, bool convert) {
std::get<0>(value).load(args, convert);
std::get<1>(value).load(kwargs, convert);
@ -734,11 +734,11 @@ public:
return type_descr(_("Tuple[") + element_names() + _("]"));
}
template <typename ReturnValue, typename Func> typename std::enable_if<!std::is_void<ReturnValue>::value, ReturnValue>::type call(Func &&f) {
template <typename ReturnValue, typename Func> enable_if_t<!std::is_void<ReturnValue>::value, ReturnValue> call(Func &&f) {
return call<ReturnValue>(std::forward<Func>(f), typename make_index_sequence<sizeof...(Tuple)>::type());
}
template <typename ReturnValue, typename Func> typename std::enable_if<std::is_void<ReturnValue>::value, void_type>::type call(Func &&f) {
template <typename ReturnValue, typename Func> enable_if_t<std::is_void<ReturnValue>::value, void_type> call(Func &&f) {
call<ReturnValue>(std::forward<Func>(f), typename make_index_sequence<sizeof...(Tuple)>::type());
return void_type();
}
@ -908,12 +908,12 @@ template <> struct handle_type_name<args> { static PYBIND11_DESCR name() { retur
template <> struct handle_type_name<kwargs> { static PYBIND11_DESCR name() { return _("**kwargs"); } };
template <typename type>
struct type_caster<type, typename std::enable_if<std::is_base_of<handle, type>::value>::type> {
struct type_caster<type, enable_if_t<std::is_base_of<handle, type>::value>> {
public:
template <typename T = type, typename std::enable_if<!std::is_base_of<object, T>::value, int>::type = 0>
template <typename T = type, enable_if_t<!std::is_base_of<object, T>::value, int> = 0>
bool load(handle src, bool /* convert */) { value = type(src); return value.check(); }
template <typename T = type, typename std::enable_if<std::is_base_of<object, T>::value, int>::type = 0>
template <typename T = type, enable_if_t<std::is_base_of<object, T>::value, int> = 0>
bool load(handle src, bool /* convert */) { value = type(src, true); return value.check(); }
static handle cast(const handle &src, return_value_policy /* policy */, handle /* parent */) {
@ -932,21 +932,21 @@ public:
// must have ref_count() == 1)h
// If any of the above are not satisfied, we fall back to copying.
template <typename T, typename SFINAE = void> struct move_is_plain_type : std::false_type {};
template <typename T> struct move_is_plain_type<T, typename std::enable_if<
template <typename T> struct move_is_plain_type<T, enable_if_t<
!std::is_void<T>::value && !std::is_pointer<T>::value && !std::is_reference<T>::value && !std::is_const<T>::value
>::type> : std::true_type {};
>> : std::true_type { };
template <typename T, typename SFINAE = void> struct move_always : std::false_type {};
template <typename T> struct move_always<T, typename std::enable_if<
template <typename T> struct move_always<T, enable_if_t<
move_is_plain_type<T>::value &&
!std::is_copy_constructible<T>::value && std::is_move_constructible<T>::value &&
std::is_same<decltype(std::declval<type_caster<T>>().operator T&()), T&>::value
>::type> : std::true_type {};
>> : std::true_type { };
template <typename T, typename SFINAE = void> struct move_if_unreferenced : std::false_type {};
template <typename T> struct move_if_unreferenced<T, typename std::enable_if<
template <typename T> struct move_if_unreferenced<T, enable_if_t<
move_is_plain_type<T>::value &&
!move_always<T>::value && std::is_move_constructible<T>::value &&
std::is_same<decltype(std::declval<type_caster<T>>().operator T&()), T&>::value
>::type> : std::true_type {};
>> : std::true_type { };
template <typename T> using move_never = std::integral_constant<bool, !move_always<T>::value && !move_if_unreferenced<T>::value>;
// Detect whether returning a `type` from a cast on type's type_caster is going to result in a

View File

@ -442,14 +442,14 @@ PYBIND11_RUNTIME_EXCEPTION(reference_cast_error, PyExc_RuntimeError) /// Used in
template <typename T, typename SFINAE = void> struct format_descriptor { };
template <typename T> struct format_descriptor<T, typename std::enable_if<std::is_integral<T>::value>::type> {
template <typename T> struct format_descriptor<T, detail::enable_if_t<std::is_integral<T>::value>> {
static constexpr const char value[2] =
{ "bBhHiIqQ"[detail::log2(sizeof(T))*2 + (std::is_unsigned<T>::value ? 1 : 0)], '\0' };
static std::string format() { return value; }
};
template <typename T> constexpr const char format_descriptor<
T, typename std::enable_if<std::is_integral<T>::value>::type>::value[2];
T, detail::enable_if_t<std::is_integral<T>::value>>::value[2];
/// RAII wrapper that temporarily clears any Python error state
struct error_scope {

View File

@ -86,11 +86,11 @@ template <size_t...Digits> struct int_to_str<0, Digits...> {
// Ternary description (like std::conditional)
template <bool B, size_t Size1, size_t Size2>
constexpr typename std::enable_if<B, descr<Size1 - 1, 0>>::type _(char const(&text1)[Size1], char const(&)[Size2]) {
constexpr enable_if_t<B, descr<Size1 - 1, 0>> _(char const(&text1)[Size1], char const(&)[Size2]) {
return _(text1);
}
template <bool B, size_t Size1, size_t Size2>
constexpr typename std::enable_if<!B, descr<Size2 - 1, 0>>::type _(char const(&)[Size1], char const(&text2)[Size2]) {
constexpr enable_if_t<!B, descr<Size2 - 1, 0>> _(char const(&)[Size1], char const(&text2)[Size2]) {
return _(text2);
}
@ -164,8 +164,8 @@ PYBIND11_NOINLINE inline descr _(const char *text) {
return descr(text, types);
}
template <bool B> PYBIND11_NOINLINE typename std::enable_if<B, descr>::type _(const char *text1, const char *) { return _(text1); }
template <bool B> PYBIND11_NOINLINE typename std::enable_if<!B, descr>::type _(char const *, const char *text2) { return _(text2); }
template <bool B> PYBIND11_NOINLINE enable_if_t<B, descr> _(const char *text1, const char *) { return _(text1); }
template <bool B> PYBIND11_NOINLINE enable_if_t<!B, descr> _(char const *, const char *text2) { return _(text2); }
template <typename Type> PYBIND11_NOINLINE descr _() {
const std::type_info *types[2] = { &typeid(Type), nullptr };

View File

@ -46,9 +46,9 @@ public:
// type_caster to handle argument copying/forwarding.
template <typename T> class is_eigen_ref {
private:
template<typename Derived> static typename std::enable_if<
template<typename Derived> static enable_if_t<
std::is_same<typename std::remove_const<T>::type, Eigen::Ref<Derived>>::value,
Derived>::type test(const Eigen::Ref<Derived> &);
Derived> test(const Eigen::Ref<Derived> &);
static void test(...);
public:
typedef decltype(test(std::declval<T>())) Derived;
@ -77,7 +77,7 @@ public:
};
template<typename Type>
struct type_caster<Type, typename std::enable_if<is_eigen_dense<Type>::value && !is_eigen_ref<Type>::value>::type> {
struct type_caster<Type, enable_if_t<is_eigen_dense<Type>::value && !is_eigen_ref<Type>::value>> {
typedef typename Type::Scalar Scalar;
static constexpr bool rowMajor = Type::Flags & Eigen::RowMajorBit;
static constexpr bool isVector = Type::IsVectorAtCompileTime;
@ -149,18 +149,18 @@ struct type_caster<Type, typename std::enable_if<is_eigen_dense<Type>::value &&
_("[") + rows() + _(", ") + cols() + _("]]"));
protected:
template <typename T = Type, typename std::enable_if<T::RowsAtCompileTime == Eigen::Dynamic, int>::type = 0>
template <typename T = Type, enable_if_t<T::RowsAtCompileTime == Eigen::Dynamic, int> = 0>
static PYBIND11_DESCR rows() { return _("m"); }
template <typename T = Type, typename std::enable_if<T::RowsAtCompileTime != Eigen::Dynamic, int>::type = 0>
template <typename T = Type, enable_if_t<T::RowsAtCompileTime != Eigen::Dynamic, int> = 0>
static PYBIND11_DESCR rows() { return _<T::RowsAtCompileTime>(); }
template <typename T = Type, typename std::enable_if<T::ColsAtCompileTime == Eigen::Dynamic, int>::type = 0>
template <typename T = Type, enable_if_t<T::ColsAtCompileTime == Eigen::Dynamic, int> = 0>
static PYBIND11_DESCR cols() { return _("n"); }
template <typename T = Type, typename std::enable_if<T::ColsAtCompileTime != Eigen::Dynamic, int>::type = 0>
template <typename T = Type, enable_if_t<T::ColsAtCompileTime != Eigen::Dynamic, int> = 0>
static PYBIND11_DESCR cols() { return _<T::ColsAtCompileTime>(); }
};
template<typename Type>
struct type_caster<Type, typename std::enable_if<is_eigen_dense<Type>::value && is_eigen_ref<Type>::value>::type> {
struct type_caster<Type, enable_if_t<is_eigen_dense<Type>::value && is_eigen_ref<Type>::value>> {
protected:
using Derived = typename std::remove_const<typename is_eigen_ref<Type>::Derived>::type;
using DerivedCaster = type_caster<Derived>;
@ -181,7 +181,7 @@ public:
// type_caster for special matrix types (e.g. DiagonalMatrix): load() is not supported, but we can
// cast them into the python domain by first copying to a regular Eigen::Matrix, then casting that.
template <typename Type>
struct type_caster<Type, typename std::enable_if<is_eigen_base<Type>::value && !is_eigen_ref<Type>::value>::type> {
struct type_caster<Type, enable_if_t<is_eigen_base<Type>::value && !is_eigen_ref<Type>::value>> {
protected:
using Matrix = Eigen::Matrix<typename Type::Scalar, Eigen::Dynamic, Eigen::Dynamic>;
using MatrixCaster = type_caster<Matrix>;
@ -198,7 +198,7 @@ public:
};
template<typename Type>
struct type_caster<Type, typename std::enable_if<is_eigen_sparse<Type>::value>::type> {
struct type_caster<Type, enable_if_t<is_eigen_sparse<Type>::value>> {
typedef typename Type::Scalar Scalar;
typedef typename std::remove_reference<decltype(*std::declval<Type>().outerIndexPtr())>::type StorageIndex;
typedef typename Type::Index Index;

View File

@ -486,7 +486,7 @@ public:
};
template <typename T>
struct format_descriptor<T, typename std::enable_if<detail::is_pod_struct<T>::value>::type> {
struct format_descriptor<T, detail::enable_if_t<detail::is_pod_struct<T>::value>> {
static std::string format() {
return detail::npy_format_descriptor<typename std::remove_cv<T>::type>::format();
}
@ -517,7 +517,7 @@ struct is_pod_struct {
!std::is_same<typename std::remove_cv<T>::type, std::complex<double>>::value };
};
template <typename T> struct npy_format_descriptor<T, typename std::enable_if<std::is_integral<T>::value>::type> {
template <typename T> struct npy_format_descriptor<T, enable_if_t<std::is_integral<T>::value>> {
private:
constexpr static const int values[8] = {
npy_api::NPY_BYTE_, npy_api::NPY_UBYTE_, npy_api::NPY_SHORT_, npy_api::NPY_USHORT_,
@ -529,13 +529,13 @@ public:
return object(ptr, true);
pybind11_fail("Unsupported buffer format!");
}
template <typename T2 = T, typename std::enable_if<std::is_signed<T2>::value, int>::type = 0>
template <typename T2 = T, enable_if_t<std::is_signed<T2>::value, int> = 0>
static PYBIND11_DESCR name() { return _("int") + _<sizeof(T)*8>(); }
template <typename T2 = T, typename std::enable_if<!std::is_signed<T2>::value, int>::type = 0>
template <typename T2 = T, enable_if_t<!std::is_signed<T2>::value, int> = 0>
static PYBIND11_DESCR name() { return _("uint") + _<sizeof(T)*8>(); }
};
template <typename T> constexpr const int npy_format_descriptor<
T, typename std::enable_if<std::is_integral<T>::value>::type>::values[8];
T, enable_if_t<std::is_integral<T>::value>>::values[8];
#define DECL_FMT(Type, NumPyName, Name) template<> struct npy_format_descriptor<Type> { \
enum { value = npy_api::NumPyName }; \
@ -568,7 +568,7 @@ struct field_descriptor {
};
template <typename T>
struct npy_format_descriptor<T, typename std::enable_if<is_pod_struct<T>::value>::type> {
struct npy_format_descriptor<T, enable_if_t<is_pod_struct<T>::value>> {
static PYBIND11_DESCR name() { return _("struct"); }
static pybind11::dtype dtype() {
@ -634,9 +634,9 @@ private:
};
template <typename T>
std::string npy_format_descriptor<T, typename std::enable_if<is_pod_struct<T>::value>::type>::format_str;
std::string npy_format_descriptor<T, enable_if_t<is_pod_struct<T>::value>>::format_str;
template <typename T>
PyObject* npy_format_descriptor<T, typename std::enable_if<is_pod_struct<T>::value>::type>::dtype_ptr = nullptr;
PyObject* npy_format_descriptor<T, enable_if_t<is_pod_struct<T>::value>>::dtype_ptr = nullptr;
// Extract name, offset and format descriptor for a struct field
#define PYBIND11_FIELD_DESCRIPTOR(Type, Field) \

View File

@ -867,7 +867,7 @@ public:
record.dealloc = dealloc;
/* Register base classes specified via template arguments to class_, if any */
bool unused[] = { (add_base<options>(record), false)... };
bool unused[] = { (add_base<options>(record), false)..., false };
(void) unused;
/* Process optional arguments, if any */
@ -881,14 +881,14 @@ public:
}
}
template <typename Base, std::enable_if_t<is_base<Base>::value, int> = 0>
template <typename Base, detail::enable_if_t<is_base<Base>::value, int> = 0>
static void add_base(detail::type_record &rec) {
rec.add_base(&typeid(Base), [](void *src) -> void * {
return static_cast<Base *>(reinterpret_cast<type *>(src));
});
}
template <typename Base, std::enable_if_t<!is_base<Base>::value, int> = 0>
template <typename Base, detail::enable_if_t<!is_base<Base>::value, int> = 0>
static void add_base(detail::type_record &) { }
template <typename Func, typename... Extra>
@ -1032,7 +1032,7 @@ private:
/// Initialize holder object, variant 2: try to construct from existing holder object, if possible
template <typename T = holder_type,
typename std::enable_if<std::is_copy_constructible<T>::value, int>::type = 0>
detail::enable_if_t<std::is_copy_constructible<T>::value, int> = 0>
static void init_holder_helper(instance_type *inst, const holder_type *holder_ptr, const void * /* dummy */) {
if (holder_ptr)
new (&inst->holder) holder_type(*holder_ptr);
@ -1042,7 +1042,7 @@ private:
/// Initialize holder object, variant 3: holder is not copy constructible (e.g. unique_ptr), always initialize from raw pointer
template <typename T = holder_type,
typename std::enable_if<!std::is_copy_constructible<T>::value, int>::type = 0>
detail::enable_if_t<!std::is_copy_constructible<T>::value, int> = 0>
static void init_holder_helper(instance_type *inst, const holder_type * /* unused */, const void * /* dummy */) {
new (&inst->holder) holder_type(inst->value);
}

View File

@ -490,7 +490,7 @@ class int_ : public object {
public:
PYBIND11_OBJECT_DEFAULT(int_, object, PYBIND11_LONG_CHECK)
template <typename T,
typename std::enable_if<std::is_integral<T>::value, int>::type = 0>
detail::enable_if_t<std::is_integral<T>::value, int> = 0>
int_(T value) {
if (sizeof(T) <= sizeof(long)) {
if (std::is_signed<T>::value)
@ -507,7 +507,7 @@ public:
}
template <typename T,
typename std::enable_if<std::is_integral<T>::value, int>::type = 0>
detail::enable_if_t<std::is_integral<T>::value, int> = 0>
operator T() const {
if (sizeof(T) <= sizeof(long)) {
if (std::is_signed<T>::value)

View File

@ -112,7 +112,7 @@ template <typename Type, typename Value> struct list_caster {
}
template <typename T = Type,
typename std::enable_if<std::is_same<decltype(std::declval<T>().reserve(0)), void>::value, int>::type = 0>
enable_if_t<std::is_same<decltype(std::declval<T>().reserve(0)), void>::value, int> = 0>
void reserve_maybe(list l, Type *) { value.reserve(l.size()); }
void reserve_maybe(list, void *) { }

View File

@ -40,20 +40,20 @@ struct is_comparable : std::false_type { };
/* For non-map data structures, check whether operator== can be instantiated */
template <typename T>
struct is_comparable<
T, typename std::enable_if<container_traits<T>::is_element &&
container_traits<T>::is_comparable>::type>
T, enable_if_t<container_traits<T>::is_element &&
container_traits<T>::is_comparable>>
: std::true_type { };
/* For a vector/map data structure, recursively check the value type (which is std::pair for maps) */
template <typename T>
struct is_comparable<T, typename std::enable_if<container_traits<T>::is_vector>::type> {
struct is_comparable<T, enable_if_t<container_traits<T>::is_vector>> {
static constexpr const bool value =
is_comparable<typename T::value_type>::value;
};
/* For pairs, recursively check the two data types */
template <typename T>
struct is_comparable<T, typename std::enable_if<container_traits<T>::is_pair>::type> {
struct is_comparable<T, enable_if_t<container_traits<T>::is_pair>> {
static constexpr const bool value =
is_comparable<typename T::first_type>::value &&
is_comparable<typename T::second_type>::value;
@ -64,13 +64,13 @@ template <typename, typename, typename... Args> void vector_if_copy_constructibl
template <typename, typename, typename... Args> void vector_if_equal_operator(const Args&...) { }
template <typename, typename, typename... Args> void vector_if_insertion_operator(const Args&...) { }
template<typename Vector, typename Class_, typename std::enable_if<std::is_copy_constructible<typename Vector::value_type>::value, int>::type = 0>
template<typename Vector, typename Class_, enable_if_t<std::is_copy_constructible<typename Vector::value_type>::value, int> = 0>
void vector_if_copy_constructible(Class_ &cl) {
cl.def(pybind11::init<const Vector &>(),
"Copy constructor");
}
template<typename Vector, typename Class_, typename std::enable_if<is_comparable<Vector>::value, int>::type = 0>
template<typename Vector, typename Class_, enable_if_t<is_comparable<Vector>::value, int> = 0>
void vector_if_equal_operator(Class_ &cl) {
using T = typename Vector::value_type;
@ -376,7 +376,7 @@ template <typename Map, typename Class_, typename... Args> void map_if_copy_assi
);
}
template<typename Map, typename Class_, typename std::enable_if<!std::is_copy_assignable<typename Map::mapped_type>::value, int>::type = 0>
template<typename Map, typename Class_, enable_if_t<!std::is_copy_assignable<typename Map::mapped_type>::value, int> = 0>
void map_if_copy_assignable(Class_ &cl) {
using KeyType = typename Map::key_type;
using MappedType = typename Map::mapped_type;