Skip to content

Commit 3aa8472

Browse files
committed
remove usage of make_caster in stl_bind.h
1 parent 4302474 commit 3aa8472

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

include/pybind11/stl_bind.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
#include "detail/common.h"
1313
#include "detail/type_caster_base.h"
1414
#include "cast.h"
15-
#include "complex.h"
16-
#include "functional.h"
1715
#include "operators.h"
1816

1917
#include <algorithm>
18+
#include <complex>
19+
#include <functional>
2020
#include <sstream>
2121
#include <type_traits>
2222

@@ -496,7 +496,7 @@ template <>
496496
struct type_mapper<std::nullptr_t> {
497497
using py_type = pybind11::none;
498498
static std::string py_name() {
499-
constexpr auto descr = detail::make_caster<std::nullptr_t>::name;
499+
constexpr auto descr = const_name("None");
500500
return descr.text;
501501
}
502502
};
@@ -505,7 +505,7 @@ template <>
505505
struct type_mapper<bool> {
506506
using py_type = pybind11::bool_;
507507
static std::string py_name() {
508-
constexpr auto descr = detail::make_caster<bool>::name;
508+
constexpr auto descr = const_name("bool");
509509
return descr.text;
510510
}
511511
};
@@ -515,7 +515,7 @@ struct type_mapper<T, enable_if_t<std::is_arithmetic<T>::value && !is_std_char_t
515515
using py_type
516516
= conditional_t<std::is_floating_point<T>::value, pybind11::float_, pybind11::int_>;
517517
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");
519519
return descr.text;
520520
}
521521
};
@@ -524,7 +524,7 @@ template <typename T>
524524
struct type_mapper<std::complex<T>> {
525525
using py_type = std::complex<typename type_mapper<T>::py_type>;
526526
static std::string py_name() {
527-
constexpr auto descr = detail::make_caster<std::complex<T>>::name;
527+
constexpr auto descr = const_name("complex");
528528
return descr.text;
529529
}
530530
};
@@ -533,7 +533,7 @@ template <typename T>
533533
struct type_mapper<T, enable_if_t<is_std_char_type<T>::value>> {
534534
using py_type = pybind11::str;
535535
static std::string py_name() {
536-
constexpr auto descr = detail::make_caster<T>::name;
536+
constexpr auto descr = const_name(PYBIND11_STRING_NAME);
537537
return descr.text;
538538
}
539539
};
@@ -542,7 +542,7 @@ template <typename T>
542542
struct type_mapper<T, enable_if_t<is_pyobject<T>::value>> {
543543
using py_type = T;
544544
static std::string py_name() {
545-
constexpr auto descr = detail::make_caster<T>::name;
545+
constexpr auto descr = handle_type_name<T>::name;
546546
return descr.text;
547547
}
548548
};
@@ -558,8 +558,7 @@ struct type_mapper<std::basic_string<CharT, Traits, Allocator>,
558558
enable_if_t<is_std_char_type<CharT>::value>> {
559559
using py_type = pybind11::str;
560560
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);
563562
return descr.text;
564563
}
565564
};
@@ -570,7 +569,7 @@ struct type_mapper<std::basic_string_view<CharT, Traits>,
570569
enable_if_t<is_std_char_type<CharT>::value>> {
571570
using py_type = pybind11::str;
572571
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);
574573
return descr.text;
575574
}
576575
};
@@ -807,8 +806,11 @@ struct KeysViewImpl : public KeysView {
807806
size_t len() override { return map.size(); }
808807
iterator iter() override { return make_key_iterator(map.begin(), map.end()); }
809808
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+
}
812814
}
813815
Map &map;
814816
};

0 commit comments

Comments
 (0)