aboutsummaryrefslogtreecommitdiffstats
path: root/3rdparty/pybind11/tests/test_tagbased_polymorphic.cpp
diff options
context:
space:
mode:
authorgatecat <gatecat@ds0.me>2022-09-14 09:28:47 +0200
committergatecat <gatecat@ds0.me>2022-09-14 09:28:47 +0200
commita72f898ff4c4237424c468044a6db9d6953b541e (patch)
tree1c4a543f661dd1b281aecf4660388491702fa8d8 /3rdparty/pybind11/tests/test_tagbased_polymorphic.cpp
parentf1349e114f3a16ccd002e8513339e18f5be4d31b (diff)
downloadnextpnr-a72f898ff4c4237424c468044a6db9d6953b541e.tar.gz
nextpnr-a72f898ff4c4237424c468044a6db9d6953b541e.tar.bz2
nextpnr-a72f898ff4c4237424c468044a6db9d6953b541e.zip
3rdparty: Bump vendored pybind11 version for py3.11 support
Signed-off-by: gatecat <gatecat@ds0.me>
Diffstat (limited to '3rdparty/pybind11/tests/test_tagbased_polymorphic.cpp')
-rw-r--r--3rdparty/pybind11/tests/test_tagbased_polymorphic.cpp117
1 files changed, 61 insertions, 56 deletions
diff --git a/3rdparty/pybind11/tests/test_tagbased_polymorphic.cpp b/3rdparty/pybind11/tests/test_tagbased_polymorphic.cpp
index 838a168d..12ba6532 100644
--- a/3rdparty/pybind11/tests/test_tagbased_polymorphic.cpp
+++ b/3rdparty/pybind11/tests/test_tagbased_polymorphic.cpp
@@ -7,11 +7,11 @@
BSD-style license that can be found in the LICENSE file.
*/
-#include "pybind11_tests.h"
#include <pybind11/stl.h>
-struct Animal
-{
+#include "pybind11_tests.h"
+
+struct Animal {
// Make this type also a "standard" polymorphic type, to confirm that
// specializing polymorphic_type_hook using enable_if_t still works
// (https://github.com/pybind/pybind11/pull/2016/).
@@ -20,55 +20,54 @@ struct Animal
// Enum for tag-based polymorphism.
enum class Kind {
Unknown = 0,
- Dog = 100, Labrador, Chihuahua, LastDog = 199,
- Cat = 200, Panther, LastCat = 299
+ Dog = 100,
+ Labrador,
+ Chihuahua,
+ LastDog = 199,
+ Cat = 200,
+ Panther,
+ LastCat = 299
};
- static const std::type_info* type_of_kind(Kind kind);
+ static const std::type_info *type_of_kind(Kind kind);
static std::string name_of_kind(Kind kind);
const Kind kind;
const std::string name;
- protected:
- Animal(const std::string& _name, Kind _kind)
- : kind(_kind), name(_name)
- {}
+protected:
+ Animal(const std::string &_name, Kind _kind) : kind(_kind), name(_name) {}
};
-struct Dog : Animal
-{
- Dog(const std::string& _name, Kind _kind = Kind::Dog) : Animal(_name, _kind) {}
+struct Dog : Animal {
+ explicit Dog(const std::string &_name, Kind _kind = Kind::Dog) : Animal(_name, _kind) {}
std::string bark() const { return name_of_kind(kind) + " " + name + " goes " + sound; }
std::string sound = "WOOF!";
};
-struct Labrador : Dog
-{
- Labrador(const std::string& _name, int _excitement = 9001)
+struct Labrador : Dog {
+ explicit Labrador(const std::string &_name, int _excitement = 9001)
: Dog(_name, Kind::Labrador), excitement(_excitement) {}
int excitement;
};
-struct Chihuahua : Dog
-{
- Chihuahua(const std::string& _name) : Dog(_name, Kind::Chihuahua) { sound = "iyiyiyiyiyi"; }
+struct Chihuahua : Dog {
+ explicit Chihuahua(const std::string &_name) : Dog(_name, Kind::Chihuahua) {
+ sound = "iyiyiyiyiyi";
+ }
std::string bark() const { return Dog::bark() + " and runs in circles"; }
};
-struct Cat : Animal
-{
- Cat(const std::string& _name, Kind _kind = Kind::Cat) : Animal(_name, _kind) {}
+struct Cat : Animal {
+ explicit Cat(const std::string &_name, Kind _kind = Kind::Cat) : Animal(_name, _kind) {}
std::string purr() const { return "mrowr"; }
};
-struct Panther : Cat
-{
- Panther(const std::string& _name) : Cat(_name, Kind::Panther) {}
+struct Panther : Cat {
+ explicit Panther(const std::string &_name) : Cat(_name, Kind::Panther) {}
std::string purr() const { return "mrrrRRRRRR"; }
};
-std::vector<std::unique_ptr<Animal>> create_zoo()
-{
+std::vector<std::unique_ptr<Animal>> create_zoo() {
std::vector<std::unique_ptr<Animal>> ret;
ret.emplace_back(new Labrador("Fido", 15000));
@@ -83,45 +82,53 @@ std::vector<std::unique_ptr<Animal>> create_zoo()
return ret;
}
-const std::type_info* Animal::type_of_kind(Kind kind)
-{
+const std::type_info *Animal::type_of_kind(Kind kind) {
switch (kind) {
- case Kind::Unknown: break;
-
- case Kind::Dog: break;
- case Kind::Labrador: return &typeid(Labrador);
- case Kind::Chihuahua: return &typeid(Chihuahua);
- case Kind::LastDog: break;
-
- case Kind::Cat: break;
- case Kind::Panther: return &typeid(Panther);
- case Kind::LastCat: break;
+ case Kind::Unknown:
+ case Kind::Dog:
+ break;
+
+ case Kind::Labrador:
+ return &typeid(Labrador);
+ case Kind::Chihuahua:
+ return &typeid(Chihuahua);
+
+ case Kind::LastDog:
+ case Kind::Cat:
+ break;
+ case Kind::Panther:
+ return &typeid(Panther);
+ case Kind::LastCat:
+ break;
}
- if (kind >= Kind::Dog && kind <= Kind::LastDog) return &typeid(Dog);
- if (kind >= Kind::Cat && kind <= Kind::LastCat) return &typeid(Cat);
+ if (kind >= Kind::Dog && kind <= Kind::LastDog) {
+ return &typeid(Dog);
+ }
+ if (kind >= Kind::Cat && kind <= Kind::LastCat) {
+ return &typeid(Cat);
+ }
return nullptr;
}
-std::string Animal::name_of_kind(Kind kind)
-{
+std::string Animal::name_of_kind(Kind kind) {
std::string raw_name = type_of_kind(kind)->name();
py::detail::clean_type_id(raw_name);
return raw_name;
}
-namespace pybind11 {
- template <typename itype>
- struct polymorphic_type_hook<itype, detail::enable_if_t<std::is_base_of<Animal, itype>::value>>
- {
- static const void *get(const itype *src, const std::type_info*& type)
- { type = src ? Animal::type_of_kind(src->kind) : nullptr; return src; }
- };
-} // namespace pybind11
+namespace PYBIND11_NAMESPACE {
+template <typename itype>
+struct polymorphic_type_hook<itype, detail::enable_if_t<std::is_base_of<Animal, itype>::value>> {
+ static const void *get(const itype *src, const std::type_info *&type) {
+ type = src ? Animal::type_of_kind(src->kind) : nullptr;
+ return src;
+ }
+};
+} // namespace PYBIND11_NAMESPACE
TEST_SUBMODULE(tagbased_polymorphic, m) {
- py::class_<Animal>(m, "Animal")
- .def_readonly("name", &Animal::name);
+ py::class_<Animal>(m, "Animal").def_readonly("name", &Animal::name);
py::class_<Dog, Animal>(m, "Dog")
.def(py::init<std::string>())
.def_readwrite("sound", &Dog::sound)
@@ -132,9 +139,7 @@ TEST_SUBMODULE(tagbased_polymorphic, m) {
py::class_<Chihuahua, Dog>(m, "Chihuahua")
.def(py::init<std::string>())
.def("bark", &Chihuahua::bark);
- py::class_<Cat, Animal>(m, "Cat")
- .def(py::init<std::string>())
- .def("purr", &Cat::purr);
+ py::class_<Cat, Animal>(m, "Cat").def(py::init<std::string>()).def("purr", &Cat::purr);
py::class_<Panther, Cat>(m, "Panther")
.def(py::init<std::string>())
.def("purr", &Panther::purr);