Skip to content

Commit 86d5f83

Browse files
committed
Simplify predicate type use
- Renamed first_t to first_of - Added first_of_t type alias for first_of<...>::type - changed std::integral_constant<bool, ...> to detail::bool_constant<...>
1 parent e7c9062 commit 86d5f83

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

include/pybind11/common.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,19 @@ using any_of_t = negation<std::is_same<bools<Predicate<Ts>::value...>,
350350
bools<always_false<Ts>::value...>>>;
351351

352352
// Extracts the first type from the template parameter pack matching the predicate, or void if none match.
353-
template <template<class> class Predicate, class... Ts> struct first_t;
354-
template <template<class> class Predicate> struct first_t<Predicate> {
353+
template <template<class> class Predicate, class... Ts> struct first_of;
354+
template <template<class> class Predicate> struct first_of<Predicate> {
355355
using type = void;
356356
};
357357
template <template<class> class Predicate, class T, class... Ts>
358-
struct first_t<Predicate, T, Ts...> {
358+
struct first_of<Predicate, T, Ts...> {
359359
using type = typename std::conditional<
360360
Predicate<T>::value,
361361
T,
362-
typename first_t<Predicate, Ts...>::type
362+
typename first_of<Predicate, Ts...>::type
363363
>::type;
364364
};
365+
template <template<class> class Predicate, class... T> using first_of_t = typename first_of<Predicate, T...>::type;
365366

366367
// Counts the number of types in the template parameter pack matching the predicate
367368
template <template<typename> class Predicate, typename... Ts> struct count_t;

include/pybind11/pybind11.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -822,20 +822,20 @@ template <typename type_, typename... options>
822822
class class_ : public detail::generic_type {
823823
template <typename T> using is_holder = detail::is_holder_type<type_, T>;
824824
template <typename T> using is_subtype = std::is_base_of<type_, T>;
825-
template <typename T> using is_base_class = std::integral_constant<bool, std::is_base_of<T, type_>::value && !std::is_same<T, type_>::value>;
825+
template <typename T> using is_base_class = detail::bool_constant<std::is_base_of<T, type_>::value && !std::is_same<T, type_>::value>;
826826
#if defined(_MSC_VER) // MSVC fails with the below type alias, unable to find the is_holder, is_subtype, etc. predicate types
827827
template <typename T> struct is_valid_class_option :
828-
std::integral_constant<bool, is_holder<T>::value || is_subtype<T>::value || is_base_class<T>::value> {};
828+
detail::bool_constant<is_holder<T>::value || is_subtype<T>::value || is_base_class<T>::value> {};
829829
#else
830830
template <typename T> using is_valid_class_option =
831-
std::integral_constant<bool, is_holder<T>::value || is_subtype<T>::value || is_base_class<T>::value>;
831+
detail::bool_constant<is_holder<T>::value || is_subtype<T>::value || is_base_class<T>::value>;
832832
#endif
833833

834-
using extracted_holder_t = typename detail::first_t<is_holder, options...>::type;
834+
using extracted_holder_t = typename detail::first_of_t<is_holder, options...>;
835835

836836
public:
837837
using type = type_;
838-
using type_alias = typename detail::first_t<is_subtype, options...>::type;
838+
using type_alias = detail::first_of_t<is_subtype, options...>;
839839
constexpr static bool has_alias = !std::is_void<type_alias>::value;
840840
using holder_type = typename std::conditional<
841841
std::is_void<extracted_holder_t>::value,

0 commit comments

Comments
 (0)