mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-26 07:02:11 +00:00
Make arg_t hold a pointer instead of a copy of the value
This commit is contained in:
parent
6f017cf658
commit
317524ffad
@ -14,18 +14,12 @@
|
|||||||
|
|
||||||
NAMESPACE_BEGIN(pybind11)
|
NAMESPACE_BEGIN(pybind11)
|
||||||
|
|
||||||
template <typename T> struct arg_t;
|
|
||||||
|
|
||||||
/// Annotation for keyword arguments
|
/// Annotation for keyword arguments
|
||||||
struct arg {
|
struct arg {
|
||||||
constexpr explicit arg(const char *name) : name(name) { }
|
constexpr explicit arg(const char *name) : name(name) { }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr arg_t<T> operator=(const T &value) const { return {name, value}; }
|
constexpr arg_t<T> operator=(const T &value) const { return {name, value}; }
|
||||||
template <typename T, size_t N>
|
|
||||||
constexpr arg_t<const T *> operator=(T const (&value)[N]) const {
|
|
||||||
return operator=((const T *) value);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *name;
|
const char *name;
|
||||||
};
|
};
|
||||||
@ -33,8 +27,9 @@ struct arg {
|
|||||||
/// Annotation for keyword arguments with default values
|
/// Annotation for keyword arguments with default values
|
||||||
template <typename T> struct arg_t : public arg {
|
template <typename T> struct arg_t : public arg {
|
||||||
constexpr arg_t(const char *name, const T &value, const char *descr = nullptr)
|
constexpr arg_t(const char *name, const T &value, const char *descr = nullptr)
|
||||||
: arg(name), value(value), descr(descr) { }
|
: arg(name), value(&value), descr(descr) { }
|
||||||
T value;
|
|
||||||
|
const T *value;
|
||||||
const char *descr;
|
const char *descr;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -246,7 +241,7 @@ struct process_attribute<arg_t<T>> : process_attribute_default<arg_t<T>> {
|
|||||||
|
|
||||||
/* Convert keyword value into a Python object */
|
/* Convert keyword value into a Python object */
|
||||||
object o = object(detail::type_caster<typename detail::intrinsic_type<T>::type>::cast(
|
object o = object(detail::type_caster<typename detail::intrinsic_type<T>::type>::cast(
|
||||||
a.value, return_value_policy::automatic, handle()), false);
|
*a.value, return_value_policy::automatic, handle()), false);
|
||||||
|
|
||||||
if (!o) {
|
if (!o) {
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
|
@ -17,6 +17,7 @@ NAMESPACE_BEGIN(pybind11)
|
|||||||
|
|
||||||
/* A few forward declarations */
|
/* A few forward declarations */
|
||||||
class object; class str; class object; class dict; class iterator;
|
class object; class str; class object; class dict; class iterator;
|
||||||
|
struct arg; template <typename T> struct arg_t;
|
||||||
namespace detail { class accessor; class args_proxy; class kwargs_proxy; }
|
namespace detail { class accessor; class args_proxy; class kwargs_proxy; }
|
||||||
|
|
||||||
/// Holds a reference to a Python object (no reference counting)
|
/// Holds a reference to a Python object (no reference counting)
|
||||||
|
Loading…
Reference in New Issue
Block a user