Skip to content

Changing PYBIND11_SMART_HOLDER_TYPE_CASTERS to use __VA_ARGS__. #2954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions include/pybind11/detail/smart_holder_type_casters.h
Original file line number Diff line number Diff line change
Expand Up @@ -773,28 +773,28 @@ struct smart_holder_type_caster<std::unique_ptr<T const, D>>

#ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT

# define PYBIND11_SMART_HOLDER_TYPE_CASTERS(T) \
# define PYBIND11_SMART_HOLDER_TYPE_CASTERS(...) \
namespace pybind11 { \
namespace detail { \
template <> \
class type_caster<T> : public smart_holder_type_caster<T> {}; \
class type_caster<__VA_ARGS__> : public smart_holder_type_caster<__VA_ARGS__> {}; \
template <> \
class type_caster<std::shared_ptr<T>> \
: public smart_holder_type_caster<std::shared_ptr<T>> {}; \
class type_caster<std::shared_ptr<__VA_ARGS__>> \
: public smart_holder_type_caster<std::shared_ptr<__VA_ARGS__>> {}; \
template <> \
class type_caster<std::shared_ptr<T const>> \
: public smart_holder_type_caster<std::shared_ptr<T const>> {}; \
class type_caster<std::shared_ptr<__VA_ARGS__ const>> \
: public smart_holder_type_caster<std::shared_ptr<__VA_ARGS__ const>> {}; \
template <typename D> \
class type_caster<std::unique_ptr<T, D>> \
: public smart_holder_type_caster<std::unique_ptr<T, D>> {}; \
class type_caster<std::unique_ptr<__VA_ARGS__, D>> \
: public smart_holder_type_caster<std::unique_ptr<__VA_ARGS__, D>> {}; \
template <typename D> \
class type_caster<std::unique_ptr<T const, D>> \
: public smart_holder_type_caster<std::unique_ptr<T const, D>> {}; \
class type_caster<std::unique_ptr<__VA_ARGS__ const, D>> \
: public smart_holder_type_caster<std::unique_ptr<__VA_ARGS__ const, D>> {}; \
} \
}
#else

# define PYBIND11_SMART_HOLDER_TYPE_CASTERS(T)
# define PYBIND11_SMART_HOLDER_TYPE_CASTERS(...)

template <typename T>
class type_caster_for_class_ : public smart_holder_type_caster<T> {};
Expand Down
6 changes: 3 additions & 3 deletions include/pybind11/smart_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)

// Supports easier switching between py::class_<U> and py::class_<U, py::smart_holder>:
// 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.
// Note though that the PYBIND11_SMART_HOLDER_TYPE_CASTERS(U) macro also needs to be
// added (for `classh`) or commented out (for `class_`).
// Note though that the PYBIND11_SMART_HOLDER_TYPE_CASTERS(T) macro also needs to be
// added (for `classh`) or commented out (when falling back to `class_`).
template <typename type_, typename... options>
class classh : public class_<type_, smart_holder, options...> {
public:
Expand Down