Move classh into pybind11/pybind11.h and update test_classh_mock.cpp accordingly.

This commit is contained in:
Ralf W. Grosse-Kunstleve 2024-07-20 17:53:37 -07:00
parent 9f9a698ee9
commit d0003f5660
3 changed files with 22 additions and 22 deletions

View File

@ -2308,6 +2308,18 @@ private:
}
};
#ifdef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
// Supports easier switching between py::class_<T> and py::class_<T, py::smart_holder>:
// users can simply replace the `_` in `class_` with `h` or vice versa.
template <typename type_, typename... options>
class classh : public class_<type_, smart_holder, options...> {
public:
using class_<type_, smart_holder, options...>::class_;
};
#endif
/// Binds an existing constructor taking arguments Args...
template <typename... Args>
detail::initimpl::constructor<Args...> init() {

View File

@ -6,23 +6,9 @@
#include "pybind11.h"
// Legacy macros introduced with smart_holder_type_casters implementation in 2021.
// Deprecated.
#define PYBIND11_TYPE_CASTER_BASE_HOLDER(...)
#define PYBIND11_SMART_HOLDER_TYPE_CASTERS(...)
#define PYBIND11_SH_AVL(...) // "Smart_Holder if AVaiLable"
#define PYBIND11_SH_DEF(...) // "Smart_Holder if DEFault"
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
#ifdef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
// Supports easier switching between py::class_<T> and py::class_<T, py::smart_holder>:
// users can simply replace the `_` in `class_` with `h` or vice versa.
template <typename type_, typename... options>
class classh : public class_<type_, smart_holder, options...> {
public:
using class_<type_, smart_holder, options...>::class_;
};
#endif
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)

View File

@ -1,18 +1,20 @@
#include "pybind11_tests.h"
// The main purpose of this test is to ensure the suggested BOILERPLATE code block below is
// correct.
// The main purpose of this test was to ensure that the suggested
// BOILERPLATE code block (NOW DEPRECATED!) block below is correct.
// Copy this block of code into your project.
// Replace FOOEXT with the name of your project.
// BOILERPLATE BEGIN
// BOILERPLATE BEGIN DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED
#ifdef FOOEXT_USING_PYBIND11_SMART_HOLDER
# include <pybind11/smart_holder.h>
#else
# include <pybind11/pybind11.h>
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
# ifndef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
template <typename type_, typename... options>
using classh = class_<type_, options...>;
# endif
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
# ifndef PYBIND11_SH_AVL
# define PYBIND11_SH_AVL(...) std::shared_ptr<__VA_ARGS__> // "Smart_Holder if AVaiLable"
@ -27,7 +29,7 @@ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
# define PYBIND11_TYPE_CASTER_BASE_HOLDER(...)
# endif
#endif
// BOILERPLATE END
// BOILERPLATE END DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED
namespace {
struct FooUc {};
@ -37,8 +39,8 @@ struct FooSc {};
struct FooSp {};
} // namespace
PYBIND11_SMART_HOLDER_TYPE_CASTERS(FooUp)
PYBIND11_SMART_HOLDER_TYPE_CASTERS(FooSp)
PYBIND11_SMART_HOLDER_TYPE_CASTERS(FooUp) // DEPRECATED
PYBIND11_SMART_HOLDER_TYPE_CASTERS(FooSp) // DEPRECATED
PYBIND11_TYPE_CASTER_BASE_HOLDER(FooSa, std::shared_ptr<FooSa>)