12
12
#include " detail/common.h"
13
13
#include " detail/type_caster_base.h"
14
14
#include " cast.h"
15
- #include " complex.h"
16
- #include " functional.h"
17
15
#include " operators.h"
18
16
19
17
#include < algorithm>
18
+ #include < complex>
19
+ #include < functional>
20
20
#include < sstream>
21
21
#include < type_traits>
22
22
@@ -496,7 +496,7 @@ template <>
496
496
struct type_mapper <std::nullptr_t > {
497
497
using py_type = pybind11::none;
498
498
static std::string py_name () {
499
- constexpr auto descr = detail::make_caster<std:: nullptr_t >::name ;
499
+ constexpr auto descr = const_name ( " None " ) ;
500
500
return descr.text ;
501
501
}
502
502
};
@@ -505,7 +505,7 @@ template <>
505
505
struct type_mapper <bool > {
506
506
using py_type = pybind11::bool_;
507
507
static std::string py_name () {
508
- constexpr auto descr = detail::make_caster< bool >::name ;
508
+ constexpr auto descr = const_name ( " bool" ) ;
509
509
return descr.text ;
510
510
}
511
511
};
@@ -515,7 +515,7 @@ struct type_mapper<T, enable_if_t<std::is_arithmetic<T>::value && !is_std_char_t
515
515
using py_type
516
516
= conditional_t <std::is_floating_point<T>::value, pybind11::float_, pybind11::int_>;
517
517
static std::string py_name () {
518
- constexpr auto descr = detail::make_caster <T>::name ;
518
+ constexpr auto descr = const_name<std::is_integral <T>::value>( " int " , " float " ) ;
519
519
return descr.text ;
520
520
}
521
521
};
@@ -524,7 +524,7 @@ template <typename T>
524
524
struct type_mapper <std::complex<T>> {
525
525
using py_type = std::complex<typename type_mapper<T>::py_type>;
526
526
static std::string py_name () {
527
- constexpr auto descr = detail::make_caster<std:: complex<T>>::name ;
527
+ constexpr auto descr = const_name ( " complex" ) ;
528
528
return descr.text ;
529
529
}
530
530
};
@@ -533,7 +533,7 @@ template <typename T>
533
533
struct type_mapper <T, enable_if_t <is_std_char_type<T>::value>> {
534
534
using py_type = pybind11::str;
535
535
static std::string py_name () {
536
- constexpr auto descr = detail::make_caster<T>::name ;
536
+ constexpr auto descr = const_name (PYBIND11_STRING_NAME) ;
537
537
return descr.text ;
538
538
}
539
539
};
@@ -542,7 +542,7 @@ template <typename T>
542
542
struct type_mapper <T, enable_if_t <is_pyobject<T>::value>> {
543
543
using py_type = T;
544
544
static std::string py_name () {
545
- constexpr auto descr = detail::make_caster <T>::name;
545
+ constexpr auto descr = handle_type_name <T>::name;
546
546
return descr.text ;
547
547
}
548
548
};
@@ -558,8 +558,7 @@ struct type_mapper<std::basic_string<CharT, Traits, Allocator>,
558
558
enable_if_t <is_std_char_type<CharT>::value>> {
559
559
using py_type = pybind11::str;
560
560
static std::string py_name () {
561
- constexpr auto descr
562
- = detail::make_caster<std::basic_string<CharT, Traits, Allocator>>::name;
561
+ constexpr auto descr = const_name (PYBIND11_STRING_NAME);
563
562
return descr.text ;
564
563
}
565
564
};
@@ -570,7 +569,7 @@ struct type_mapper<std::basic_string_view<CharT, Traits>,
570
569
enable_if_t <is_std_char_type<CharT>::value>> {
571
570
using py_type = pybind11::str;
572
571
static std::string py_name () {
573
- constexpr auto descr = detail::make_caster<std::basic_string_view<CharT, Traits>>::name ;
572
+ constexpr auto descr = const_name (PYBIND11_STRING_NAME) ;
574
573
return descr.text ;
575
574
}
576
575
};
@@ -807,8 +806,11 @@ struct KeysViewImpl : public KeysView {
807
806
size_t len () override { return map.size (); }
808
807
iterator iter () override { return make_key_iterator (map.begin (), map.end ()); }
809
808
bool contains (const handle &k) override {
810
- return detail::make_caster<typename Map::key_type>().load (k, true )
811
- && map.find (k.template cast <typename Map::key_type>()) != map.end ();
809
+ try {
810
+ return map.find (k.template cast <typename Map::key_type>()) != map.end ();
811
+ } catch (const cast_error &) {
812
+ return false ;
813
+ }
812
814
}
813
815
Map ↦
814
816
};
0 commit comments