Loading...
Searching...
No Matches
pySignatureExt.h
1//
2// Copyright 2023 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_TF_PY_SIGNATURE_EXT_H
8#define PXR_BASE_TF_PY_SIGNATURE_EXT_H
9
10#include <boost/mpl/vector.hpp>
11
12// This file extends boost::python::detail::get_signature to support member
13// function pointers that have lvalue ref-qualifiers. For example:
14//
15// class Foo {
16// void f() &;
17// };
18//
19// Without this extension, boost::python cannot wrap ref-qualified member
20// functions like this.
21//
22// This utility does not support rvalue ref-qualifiers. There isn't really such
23// a thing as an rvalue in Python, so it doesn't make sense to wrap rvalue
24// ref-qualified member functions. And boost.python's infrastructure always
25// requires an lvalue for 'this' accordingly.
26//
27// To use this utility, #include this file before any other file in your
28// wrapXXX.cpp file; the order matters.
29
30namespace boost { namespace python { namespace detail {
31
32template <class Ret, class TheCls, class ... Args>
33auto get_signature(Ret (TheCls::*)(Args...) &, void* =nullptr) {
34 return boost::mpl::vector<Ret, TheCls &, Args...>();
35}
36template <class Ret, class TheCls, class ... Args>
37auto get_signature(Ret (TheCls::*)(Args...) const &, void* =nullptr) {
38 return boost::mpl::vector<Ret, TheCls &, Args...>();
39}
40
41}}}
42
43#include <boost/python/signature.hpp>
44
45#endif // PXR_BASE_TF_PY_SIGNATURE_EXT_H