aboutsummaryrefslogtreecommitdiffstats
path: root/3rdparty/pybind11/tests/test_stl.cpp
diff options
context:
space:
mode:
authorMiodrag Milanovic <mmicko@gmail.com>2021-01-02 10:15:39 +0100
committerMiodrag Milanovic <mmicko@gmail.com>2021-01-02 10:15:39 +0100
commite76cdab6dd77bad411e6ac9372ee527aff89ef17 (patch)
treee9868f05cf455336d75f33b1312d71034f8fb334 /3rdparty/pybind11/tests/test_stl.cpp
parentc6cdf30501dcb2da01361229dd66a05dad73a132 (diff)
downloadnextpnr-e76cdab6dd77bad411e6ac9372ee527aff89ef17.tar.gz
nextpnr-e76cdab6dd77bad411e6ac9372ee527aff89ef17.tar.bz2
nextpnr-e76cdab6dd77bad411e6ac9372ee527aff89ef17.zip
Update pybind11 to version 2.6.1
Diffstat (limited to '3rdparty/pybind11/tests/test_stl.cpp')
-rw-r--r--3rdparty/pybind11/tests/test_stl.cpp44
1 files changed, 42 insertions, 2 deletions
diff --git a/3rdparty/pybind11/tests/test_stl.cpp b/3rdparty/pybind11/tests/test_stl.cpp
index 207c9fb2..05901627 100644
--- a/3rdparty/pybind11/tests/test_stl.cpp
+++ b/3rdparty/pybind11/tests/test_stl.cpp
@@ -15,7 +15,7 @@
#include <string>
// Test with `std::variant` in C++17 mode, or with `boost::variant` in C++11/14
-#if PYBIND11_HAS_VARIANT
+#if defined(PYBIND11_HAS_VARIANT)
using std::variant;
#elif defined(PYBIND11_TEST_BOOST) && (!defined(_MSC_VER) || _MSC_VER >= 1910)
# include <boost/variant.hpp>
@@ -47,7 +47,18 @@ struct TplCtorClass {
namespace std {
template <>
struct hash<TplCtorClass> { size_t operator()(const TplCtorClass &) const { return 0; } };
-}
+} // namespace std
+
+
+template <template <typename> class OptionalImpl, typename T>
+struct OptionalHolder
+{
+ OptionalHolder() = default;
+ bool member_initialized() const {
+ return member && member->initialized;
+ }
+ OptionalImpl<T> member = T{};
+};
TEST_SUBMODULE(stl, m) {
@@ -154,6 +165,23 @@ TEST_SUBMODULE(stl, m) {
.def(py::init<>())
.def(py::init<int>());
+
+ struct MoveOutDetector
+ {
+ MoveOutDetector() = default;
+ MoveOutDetector(const MoveOutDetector&) = default;
+ MoveOutDetector(MoveOutDetector&& other) noexcept
+ : initialized(other.initialized) {
+ // steal underlying resource
+ other.initialized = false;
+ }
+ bool initialized = true;
+ };
+ py::class_<MoveOutDetector>(m, "MoveOutDetector", "Class with move tracking")
+ .def(py::init<>())
+ .def_readonly("initialized", &MoveOutDetector::initialized);
+
+
#ifdef PYBIND11_HAS_OPTIONAL
// test_optional
m.attr("has_optional") = true;
@@ -175,6 +203,12 @@ TEST_SUBMODULE(stl, m) {
m.def("nodefer_none_optional", [](std::optional<int>) { return true; });
m.def("nodefer_none_optional", [](py::none) { return false; });
+
+ using opt_holder = OptionalHolder<std::optional, MoveOutDetector>;
+ py::class_<opt_holder>(m, "OptionalHolder", "Class with optional member")
+ .def(py::init<>())
+ .def_readonly("member", &opt_holder::member)
+ .def("member_initialized", &opt_holder::member_initialized);
#endif
#ifdef PYBIND11_HAS_EXP_OPTIONAL
@@ -195,6 +229,12 @@ TEST_SUBMODULE(stl, m) {
m.def("test_no_assign_exp", [](const exp_opt_no_assign &x) {
return x ? x->value : 42;
}, py::arg_v("x", std::experimental::nullopt, "None"));
+
+ using opt_exp_holder = OptionalHolder<std::experimental::optional, MoveOutDetector>;
+ py::class_<opt_exp_holder>(m, "OptionalExpHolder", "Class with optional member")
+ .def(py::init<>())
+ .def_readonly("member", &opt_exp_holder::member)
+ .def("member_initialized", &opt_exp_holder::member_initialized);
#endif
#ifdef PYBIND11_HAS_VARIANT