mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
Make overload_cast_impl available in C++11 mode. (#1581)
* Make `overload_cast_impl` available in C++11 mode. Narrow the scope of the `#if defined(PYBIND11_CPP14)` block around overload_cast to only cover the parts where C++14 is stricly required. Thus, the implementation in `pybind11::details::overload_cast_impl` is still available in C++11 mode. * PR #1581: Modify test to use overload_cast_impl, update docs and change log
This commit is contained in:
committed by
Wenzel Jakob
parent
04c8f4b56e
commit
19189b4c2c
@@ -11,6 +11,11 @@
|
||||
#include "pybind11_tests.h"
|
||||
#include "constructor_stats.h"
|
||||
|
||||
#if !defined(PYBIND11_OVERLOAD_CAST)
|
||||
template <typename... Args>
|
||||
using overload_cast_ = pybind11::detail::overload_cast_impl<Args...>;
|
||||
#endif
|
||||
|
||||
class ExampleMandA {
|
||||
public:
|
||||
ExampleMandA() { print_default_created(this); }
|
||||
@@ -242,15 +247,16 @@ TEST_SUBMODULE(methods_and_attributes, m) {
|
||||
.def("overloaded_const", py::overload_cast<int, int>(&ExampleMandA::overloaded, py::const_))
|
||||
.def("overloaded_const", py::overload_cast<float, float>(&ExampleMandA::overloaded, py::const_))
|
||||
#else
|
||||
.def("overloaded", static_cast<py::str (ExampleMandA::*)()>(&ExampleMandA::overloaded))
|
||||
.def("overloaded", static_cast<py::str (ExampleMandA::*)(int)>(&ExampleMandA::overloaded))
|
||||
.def("overloaded", static_cast<py::str (ExampleMandA::*)(int, float)>(&ExampleMandA::overloaded))
|
||||
// Use both the traditional static_cast method and the C++11 compatible overload_cast_
|
||||
.def("overloaded", overload_cast_<>()(&ExampleMandA::overloaded))
|
||||
.def("overloaded", overload_cast_<int>()(&ExampleMandA::overloaded))
|
||||
.def("overloaded", overload_cast_<int, float>()(&ExampleMandA::overloaded))
|
||||
.def("overloaded", static_cast<py::str (ExampleMandA::*)(float, int)>(&ExampleMandA::overloaded))
|
||||
.def("overloaded", static_cast<py::str (ExampleMandA::*)(int, int)>(&ExampleMandA::overloaded))
|
||||
.def("overloaded", static_cast<py::str (ExampleMandA::*)(float, float)>(&ExampleMandA::overloaded))
|
||||
.def("overloaded_float", static_cast<py::str (ExampleMandA::*)(float, float)>(&ExampleMandA::overloaded))
|
||||
.def("overloaded_const", static_cast<py::str (ExampleMandA::*)(int ) const>(&ExampleMandA::overloaded))
|
||||
.def("overloaded_const", static_cast<py::str (ExampleMandA::*)(int, float) const>(&ExampleMandA::overloaded))
|
||||
.def("overloaded_float", overload_cast_<float, float>()(&ExampleMandA::overloaded))
|
||||
.def("overloaded_const", overload_cast_<int >()(&ExampleMandA::overloaded, py::const_))
|
||||
.def("overloaded_const", overload_cast_<int, float>()(&ExampleMandA::overloaded, py::const_))
|
||||
.def("overloaded_const", static_cast<py::str (ExampleMandA::*)(float, int) const>(&ExampleMandA::overloaded))
|
||||
.def("overloaded_const", static_cast<py::str (ExampleMandA::*)(int, int) const>(&ExampleMandA::overloaded))
|
||||
.def("overloaded_const", static_cast<py::str (ExampleMandA::*)(float, float) const>(&ExampleMandA::overloaded))
|
||||
|
||||
Reference in New Issue
Block a user