[CI] Now using clang-format from pip (#662)

This commit is contained in:
Philippe Tillet
2022-09-15 16:24:37 -07:00
committed by GitHub
parent 43be75ad42
commit 80e3fb5270
15 changed files with 126 additions and 125 deletions

View File

@@ -156,7 +156,7 @@ private:
private: private:
template <BufferT::BufferKind Kind, typename KeyType, typename... Args> template <BufferT::BufferKind Kind, typename KeyType, typename... Args>
void addBuffer(KeyType &key, Args &&... args) { void addBuffer(KeyType &key, Args &&...args) {
auto buffer = BufferT(Kind, std::forward<Args>(args)...); auto buffer = BufferT(Kind, std::forward<Args>(args)...);
bufferSet[buffer.id] = std::move(buffer); bufferSet[buffer.id] = std::move(buffer);
if constexpr (Kind == BufferT::BufferKind::Explicit) { if constexpr (Kind == BufferT::BufferKind::Explicit) {

View File

@@ -35,7 +35,7 @@ public:
} }
template <class F, class... Args> template <class F, class... Args>
auto enqueue(F &&f, Args &&... args) auto enqueue(F &&f, Args &&...args)
-> std::future<typename std::result_of<F(Args...)>::type> { -> std::future<typename std::result_of<F(Args...)>::type> {
using return_type = typename std::result_of<F(Args...)>::type; using return_type = typename std::result_of<F(Args...)>::type;

View File

@@ -554,13 +554,13 @@ struct process_attribute<keep_alive<Nurse, Patient>>
/// Recursively iterate over variadic template arguments /// Recursively iterate over variadic template arguments
template <typename... Args> struct process_attributes { template <typename... Args> struct process_attributes {
static void init(const Args &... args, function_record *r) { static void init(const Args &...args, function_record *r) {
int unused[] = { int unused[] = {
0, (process_attribute<typename std::decay<Args>::type>::init(args, r), 0, (process_attribute<typename std::decay<Args>::type>::init(args, r),
0)...}; 0)...};
ignore_unused(unused); ignore_unused(unused);
} }
static void init(const Args &... args, type_record *r) { static void init(const Args &...args, type_record *r) {
int unused[] = { int unused[] = {
0, (process_attribute<typename std::decay<Args>::type>::init(args, r), 0, (process_attribute<typename std::decay<Args>::type>::init(args, r),
0)...}; 0)...};

View File

@@ -1231,7 +1231,7 @@ public:
} }
template <typename T> using cast_op_type = void *&; template <typename T> using cast_op_type = void *&;
operator void * &() { return value; } operator void *&() { return value; }
static constexpr auto name = _("capsule"); static constexpr auto name = _("capsule");
private: private:
@@ -1336,9 +1336,12 @@ template <typename StringType, bool IsView = false> struct string_caster {
#endif #endif
} }
object utfNbytes = reinterpret_steal<object>(PyUnicode_AsEncodedString( object utfNbytes = reinterpret_steal<object>(
load_src.ptr(), PyUnicode_AsEncodedString(load_src.ptr(),
UTF_N == 8 ? "utf-8" : UTF_N == 16 ? "utf-16" : "utf-32", nullptr)); UTF_N == 8 ? "utf-8"
: UTF_N == 16 ? "utf-16"
: "utf-32",
nullptr));
if (!utfNbytes) { if (!utfNbytes) {
PyErr_Clear(); PyErr_Clear();
return false; return false;
@@ -1377,20 +1380,21 @@ template <typename StringType, bool IsView = false> struct string_caster {
private: private:
static handle decode_utfN(const char *buffer, ssize_t nbytes) { static handle decode_utfN(const char *buffer, ssize_t nbytes) {
#if !defined(PYPY_VERSION) #if !defined(PYPY_VERSION)
return UTF_N == 8 return UTF_N == 8 ? PyUnicode_DecodeUTF8(buffer, nbytes, nullptr)
? PyUnicode_DecodeUTF8(buffer, nbytes, nullptr) : UTF_N == 16
: UTF_N == 16 ? PyUnicode_DecodeUTF16(buffer, nbytes, nullptr, nullptr)
? PyUnicode_DecodeUTF16(buffer, nbytes, nullptr, nullptr) : PyUnicode_DecodeUTF32(buffer, nbytes, nullptr, nullptr);
: PyUnicode_DecodeUTF32(buffer, nbytes, nullptr, nullptr);
#else #else
// PyPy seems to have multiple problems related to PyUnicode_UTF*: the UTF8 // PyPy seems to have multiple problems related to PyUnicode_UTF*: the UTF8
// version sometimes segfaults for unknown reasons, while the UTF16 and 32 // version sometimes segfaults for unknown reasons, while the UTF16 and 32
// versions require a non-const char * arguments, which is also a nuisance, // versions require a non-const char * arguments, which is also a nuisance,
// so bypass the whole thing by just passing the encoding as a string value, // so bypass the whole thing by just passing the encoding as a string value,
// which works properly: // which works properly:
return PyUnicode_Decode( return PyUnicode_Decode(buffer, nbytes,
buffer, nbytes, UTF_N == 8 ? "utf-8"
UTF_N == 8 ? "utf-8" : UTF_N == 16 ? "utf-16" : "utf-32", nullptr); : UTF_N == 16 ? "utf-16"
: "utf-32",
nullptr);
#endif #endif
} }
@@ -1495,11 +1499,12 @@ public:
if (StringCaster::UTF_N == 8 && str_len > 1 && str_len <= 4) { if (StringCaster::UTF_N == 8 && str_len > 1 && str_len <= 4) {
unsigned char v0 = static_cast<unsigned char>(value[0]); unsigned char v0 = static_cast<unsigned char>(value[0]);
size_t char0_bytes = size_t char0_bytes =
!(v0 & 0x80) ? 1 : // low bits only: 0-127 !(v0 & 0x80) ? 1 : // low bits only: 0-127
(v0 & 0xE0) == 0xC0 ? 2 : // 0b110xxxxx - start of 2-byte sequence (v0 & 0xE0) == 0xC0 ? 2
(v0 & 0xF0) == 0xE0 ? 3 : // 0b110xxxxx - start of 2-byte sequence
: // 0b1110xxxx - start of 3-byte sequence (v0 & 0xF0) == 0xE0 ? 3
4; // 0b11110xxx - start of 4-byte sequence : // 0b1110xxxx - start of 3-byte sequence
4; // 0b11110xxx - start of 4-byte sequence
if (char0_bytes == str_len) { if (char0_bytes == str_len) {
// If we have a 128-255 value, we can decode it into a single char: // If we have a 128-255 value, we can decode it into a single char:
@@ -2040,7 +2045,7 @@ tuple make_tuple() {
template <return_value_policy policy = return_value_policy::automatic_reference, template <return_value_policy policy = return_value_policy::automatic_reference,
typename... Args> typename... Args>
tuple make_tuple(Args &&... args_) { tuple make_tuple(Args &&...args_) {
constexpr size_t size = sizeof...(Args); constexpr size_t size = sizeof...(Args);
std::array<object, size> args{ std::array<object, size> args{
{reinterpret_steal<object>(detail::make_caster<Args>::cast( {reinterpret_steal<object>(detail::make_caster<Args>::cast(
@@ -2261,7 +2266,7 @@ private:
template <return_value_policy policy> class simple_collector { template <return_value_policy policy> class simple_collector {
public: public:
template <typename... Ts> template <typename... Ts>
explicit simple_collector(Ts &&... values) explicit simple_collector(Ts &&...values)
: m_args(pybind11::make_tuple<policy>(std::forward<Ts>(values)...)) {} : m_args(pybind11::make_tuple<policy>(std::forward<Ts>(values)...)) {}
const tuple &args() const & { return m_args; } const tuple &args() const & { return m_args; }
@@ -2285,7 +2290,7 @@ private:
/// Python function call /// Python function call
template <return_value_policy policy> class unpacking_collector { template <return_value_policy policy> class unpacking_collector {
public: public:
template <typename... Ts> explicit unpacking_collector(Ts &&... values) { template <typename... Ts> explicit unpacking_collector(Ts &&...values) {
// Tuples aren't (easily) resizable so a list is needed for collection, // Tuples aren't (easily) resizable so a list is needed for collection,
// but the actual function call strictly requires a tuple. // but the actual function call strictly requires a tuple.
auto args_list = list(); auto args_list = list();
@@ -2407,7 +2412,7 @@ private:
/// Collect only positional arguments for a Python function call /// Collect only positional arguments for a Python function call
template <return_value_policy policy, typename... Args, template <return_value_policy policy, typename... Args,
typename = enable_if_t<all_of<is_positional<Args>...>::value>> typename = enable_if_t<all_of<is_positional<Args>...>::value>>
simple_collector<policy> collect_arguments(Args &&... args) { simple_collector<policy> collect_arguments(Args &&...args) {
return simple_collector<policy>(std::forward<Args>(args)...); return simple_collector<policy>(std::forward<Args>(args)...);
} }
@@ -2415,7 +2420,7 @@ simple_collector<policy> collect_arguments(Args &&... args) {
/// when needed) /// when needed)
template <return_value_policy policy, typename... Args, template <return_value_policy policy, typename... Args,
typename = enable_if_t<!all_of<is_positional<Args>...>::value>> typename = enable_if_t<!all_of<is_positional<Args>...>::value>>
unpacking_collector<policy> collect_arguments(Args &&... args) { unpacking_collector<policy> collect_arguments(Args &&...args) {
// Following argument order rules for generalized unpacking according to PEP // Following argument order rules for generalized unpacking according to PEP
// 448 // 448
static_assert(constexpr_last<is_positional, Args...>() < static_assert(constexpr_last<is_positional, Args...>() <
@@ -2430,14 +2435,14 @@ unpacking_collector<policy> collect_arguments(Args &&... args) {
template <typename Derived> template <typename Derived>
template <return_value_policy policy, typename... Args> template <return_value_policy policy, typename... Args>
object object_api<Derived>::operator()(Args &&... args) const { object object_api<Derived>::operator()(Args &&...args) const {
return detail::collect_arguments<policy>(std::forward<Args>(args)...) return detail::collect_arguments<policy>(std::forward<Args>(args)...)
.call(derived().ptr()); .call(derived().ptr());
} }
template <typename Derived> template <typename Derived>
template <return_value_policy policy, typename... Args> template <return_value_policy policy, typename... Args>
object object_api<Derived>::call(Args &&... args) const { object object_api<Derived>::call(Args &&...args) const {
return operator()<policy>(std::forward<Args>(args)...); return operator()<policy>(std::forward<Args>(args)...);
} }

View File

@@ -808,9 +808,9 @@ struct is_fmt_numeric<T, enable_if_t<std::is_arithmetic<T>::value>> {
? 0 ? 0
: 1 + (std::is_integral<T>::value : 1 + (std::is_integral<T>::value
? detail::log2(sizeof(T)) * 2 + std::is_unsigned<T>::value ? detail::log2(sizeof(T)) * 2 + std::is_unsigned<T>::value
: 8 + (std::is_same<T, double>::value : 8 + (std::is_same<T, double>::value ? 1
? 1 : std::is_same<T, long double>::value ? 2
: std::is_same<T, long double>::value ? 2 : 0)); : 0));
}; };
NAMESPACE_END(detail) NAMESPACE_END(detail)

View File

@@ -104,7 +104,7 @@ constexpr descr<N, Ts...> concat(const descr<N, Ts...> &descr) {
} }
template <size_t N, typename... Ts, typename... Args> template <size_t N, typename... Ts, typename... Args>
constexpr auto concat(const descr<N, Ts...> &d, const Args &... args) constexpr auto concat(const descr<N, Ts...> &d, const Args &...args)
-> decltype(std::declval<descr<N + 2, Ts...>>() + concat(args...)) { -> decltype(std::declval<descr<N + 2, Ts...>>() + concat(args...)) {
return d + _(", ") + concat(args...); return d + _(", ") + concat(args...);
} }

View File

@@ -66,13 +66,13 @@ template <typename /*Class*/> constexpr bool is_alias(void *) { return false; }
template < template <
typename Class, typename... Args, typename Class, typename... Args,
detail::enable_if_t<std::is_constructible<Class, Args...>::value, int> = 0> detail::enable_if_t<std::is_constructible<Class, Args...>::value, int> = 0>
inline Class *construct_or_initialize(Args &&... args) { inline Class *construct_or_initialize(Args &&...args) {
return new Class(std::forward<Args>(args)...); return new Class(std::forward<Args>(args)...);
} }
template < template <
typename Class, typename... Args, typename Class, typename... Args,
detail::enable_if_t<!std::is_constructible<Class, Args...>::value, int> = 0> detail::enable_if_t<!std::is_constructible<Class, Args...>::value, int> = 0>
inline Class *construct_or_initialize(Args &&... args) { inline Class *construct_or_initialize(Args &&...args) {
return new Class{std::forward<Args>(args)...}; return new Class{std::forward<Args>(args)...};
} }
@@ -200,7 +200,7 @@ void construct(value_and_holder &v_h, Alias<Class> &&result, bool) {
template <typename... Args> struct constructor { template <typename... Args> struct constructor {
template <typename Class, typename... Extra, template <typename Class, typename... Extra,
enable_if_t<!Class::has_alias, int> = 0> enable_if_t<!Class::has_alias, int> = 0>
static void execute(Class &cl, const Extra &... extra) { static void execute(Class &cl, const Extra &...extra) {
cl.def( cl.def(
"__init__", "__init__",
[](value_and_holder &v_h, Args... args) { [](value_and_holder &v_h, Args... args) {
@@ -214,7 +214,7 @@ template <typename... Args> struct constructor {
enable_if_t<Class::has_alias && enable_if_t<Class::has_alias &&
std::is_constructible<Cpp<Class>, Args...>::value, std::is_constructible<Cpp<Class>, Args...>::value,
int> = 0> int> = 0>
static void execute(Class &cl, const Extra &... extra) { static void execute(Class &cl, const Extra &...extra) {
cl.def( cl.def(
"__init__", "__init__",
[](value_and_holder &v_h, Args... args) { [](value_and_holder &v_h, Args... args) {
@@ -232,7 +232,7 @@ template <typename... Args> struct constructor {
enable_if_t<Class::has_alias && enable_if_t<Class::has_alias &&
!std::is_constructible<Cpp<Class>, Args...>::value, !std::is_constructible<Cpp<Class>, Args...>::value,
int> = 0> int> = 0>
static void execute(Class &cl, const Extra &... extra) { static void execute(Class &cl, const Extra &...extra) {
cl.def( cl.def(
"__init__", "__init__",
[](value_and_holder &v_h, Args... args) { [](value_and_holder &v_h, Args... args) {
@@ -249,7 +249,7 @@ template <typename... Args> struct alias_constructor {
enable_if_t<Class::has_alias && enable_if_t<Class::has_alias &&
std::is_constructible<Alias<Class>, Args...>::value, std::is_constructible<Alias<Class>, Args...>::value,
int> = 0> int> = 0>
static void execute(Class &cl, const Extra &... extra) { static void execute(Class &cl, const Extra &...extra) {
cl.def( cl.def(
"__init__", "__init__",
[](value_and_holder &v_h, Args... args) { [](value_and_holder &v_h, Args... args) {
@@ -280,7 +280,7 @@ struct factory<Func, void_type (*)(), Return(Args...)> {
// either already be an alias instance, or the alias needs to be constructible // either already be an alias instance, or the alias needs to be constructible
// from a `Class &&` argument. // from a `Class &&` argument.
template <typename Class, typename... Extra> template <typename Class, typename... Extra>
void execute(Class &cl, const Extra &... extra) && { void execute(Class &cl, const Extra &...extra) && {
#if defined(PYBIND11_CPP14) #if defined(PYBIND11_CPP14)
cl.def( cl.def(
"__init__", "__init__",
@@ -323,7 +323,7 @@ struct factory<CFunc, AFunc, CReturn(CArgs...), AReturn(AArgs...)> {
// the direct class (i.e. not inherited), the alias factory when `self` is a // the direct class (i.e. not inherited), the alias factory when `self` is a
// Python-side subtype. // Python-side subtype.
template <typename Class, typename... Extra> template <typename Class, typename... Extra>
void execute(Class &cl, const Extra &... extra) && { void execute(Class &cl, const Extra &...extra) && {
static_assert(Class::has_alias, static_assert(Class::has_alias,
"The two-argument version of `py::init()` can " "The two-argument version of `py::init()` can "
"only be used if the class has an alias"); "only be used if the class has an alias");
@@ -389,7 +389,7 @@ struct pickle_factory<Get, Set, RetState(Self), NewInstance(ArgState)> {
: get(std::forward<Get>(get)), set(std::forward<Set>(set)) {} : get(std::forward<Get>(get)), set(std::forward<Set>(set)) {}
template <typename Class, typename... Extra> template <typename Class, typename... Extra>
void execute(Class &cl, const Extra &... extra) && { void execute(Class &cl, const Extra &...extra) && {
cl.def("__getstate__", std::move(get)); cl.def("__getstate__", std::move(get));
#if defined(PYBIND11_CPP14) #if defined(PYBIND11_CPP14)

View File

@@ -297,7 +297,7 @@ inline type_map<type_info *> &registered_local_types_cpp() {
/// duration -- the internal strings are only cleared when the program exits or /// duration -- the internal strings are only cleared when the program exits or
/// after interpreter shutdown (when embedding), and so are suitable for c-style /// after interpreter shutdown (when embedding), and so are suitable for c-style
/// strings needed by Python internals (such as PyTypeObject's tp_name). /// strings needed by Python internals (such as PyTypeObject's tp_name).
template <typename... Args> const char *c_str(Args &&... args) { template <typename... Args> const char *c_str(Args &&...args) {
auto &strings = get_internals().static_strings; auto &strings = get_internals().static_strings;
strings.emplace_front(std::forward<Args>(args)...); strings.emplace_front(std::forward<Args>(args)...);
return strings.front().c_str(); return strings.front().c_str();

View File

@@ -164,7 +164,9 @@ template <typename Type_> struct EigenProps {
static constexpr EigenIndex static constexpr EigenIndex
inner_stride = if_zero<StrideType::InnerStrideAtCompileTime, 1>::value, inner_stride = if_zero<StrideType::InnerStrideAtCompileTime, 1>::value,
outer_stride = if_zero < StrideType::OuterStrideAtCompileTime, outer_stride = if_zero < StrideType::OuterStrideAtCompileTime,
vector ? size : row_major ? cols : rows > ::value; vector ? size
: row_major ? cols
: rows > ::value;
static constexpr bool dynamic_stride = static constexpr bool dynamic_stride =
inner_stride == Eigen::Dynamic && outer_stride == Eigen::Dynamic; inner_stride == Eigen::Dynamic && outer_stride == Eigen::Dynamic;
static constexpr bool requires_row_major = static constexpr bool requires_row_major =
@@ -471,15 +473,14 @@ private:
using props = EigenProps<Type>; using props = EigenProps<Type>;
using Scalar = typename props::Scalar; using Scalar = typename props::Scalar;
using MapType = Eigen::Map<PlainObjectType, 0, StrideType>; using MapType = Eigen::Map<PlainObjectType, 0, StrideType>;
using Array = using Array = array_t<
array_t<Scalar, array::forcecast | Scalar,
((props::row_major ? props::inner_stride array::forcecast |
: props::outer_stride) == 1 ((props::row_major ? props::inner_stride : props::outer_stride) == 1
? array::c_style ? array::c_style
: (props::row_major ? props::outer_stride : (props::row_major ? props::outer_stride : props::inner_stride) == 1
: props::inner_stride) == 1 ? array::f_style
? array::f_style : 0)>;
: 0)>;
static constexpr bool need_writeable = is_eigen_mutable_map<Type>::value; static constexpr bool need_writeable = is_eigen_mutable_map<Type>::value;
// Delay construction (these have no default constructor) // Delay construction (these have no default constructor)
std::unique_ptr<MapType> map; std::unique_ptr<MapType> map;

View File

@@ -1299,10 +1299,10 @@ private:
#define PYBIND11_FIELD_DESCRIPTOR_EX(T, Field, Name) \ #define PYBIND11_FIELD_DESCRIPTOR_EX(T, Field, Name) \
::pybind11::detail::field_descriptor { \ ::pybind11::detail::field_descriptor { \
Name, offsetof(T, Field), sizeof(decltype(std::declval<T>().Field)), \ Name, offsetof(T, Field), sizeof(decltype(std::declval<T>().Field)), \
::pybind11::format_descriptor<decltype( \ ::pybind11::format_descriptor< \
std::declval<T>().Field)>::format(), \ decltype(std::declval<T>().Field)>::format(), \
::pybind11::detail::npy_format_descriptor<decltype( \ ::pybind11::detail::npy_format_descriptor< \
std::declval<T>().Field)>::dtype() \ decltype(std::declval<T>().Field)>::dtype() \
} }
// Extract name, offset and format descriptor for a struct field // Extract name, offset and format descriptor for a struct field
@@ -1576,10 +1576,9 @@ broadcast_trivial broadcast(const std::array<buffer_info, N> &buffers,
} }
} }
return trivial_broadcast_c return trivial_broadcast_c ? broadcast_trivial::c_trivial
? broadcast_trivial::c_trivial : trivial_broadcast_f ? broadcast_trivial::f_trivial
: trivial_broadcast_f ? broadcast_trivial::f_trivial : broadcast_trivial::non_trivial;
: broadcast_trivial::non_trivial;
} }
template <typename T> struct vectorize_arg { template <typename T> struct vectorize_arg {
@@ -1643,7 +1642,7 @@ private:
// we can store vectorized buffer_infos in an array (argument VIndex has // we can store vectorized buffer_infos in an array (argument VIndex has
// its buffer at index BIndex in the array). // its buffer at index BIndex in the array).
template <size_t... Index, size_t... VIndex, size_t... BIndex> template <size_t... Index, size_t... VIndex, size_t... BIndex>
object run(typename vectorize_arg<Args>::type &... args, object run(typename vectorize_arg<Args>::type &...args,
index_sequence<Index...> i_seq, index_sequence<VIndex...> vi_seq, index_sequence<Index...> i_seq, index_sequence<VIndex...> vi_seq,
index_sequence<BIndex...> bi_seq) { index_sequence<BIndex...> bi_seq) {

View File

@@ -93,7 +93,7 @@ template <op_id, op_type, typename B, typename L, typename R> struct op_impl {};
/// Operator implementation generator /// Operator implementation generator
template <op_id id, op_type ot, typename L, typename R> struct op_ { template <op_id id, op_type ot, typename L, typename R> struct op_ {
template <typename Class, typename... Extra> template <typename Class, typename... Extra>
void execute(Class &cl, const Extra &... extra) const { void execute(Class &cl, const Extra &...extra) const {
using Base = typename Class::type; using Base = typename Class::type;
using L_type = conditional_t<std::is_same<L, self_t>::value, Base, L>; using L_type = conditional_t<std::is_same<L, self_t>::value, Base, L>;
using R_type = conditional_t<std::is_same<R, self_t>::value, Base, R>; using R_type = conditional_t<std::is_same<R, self_t>::value, Base, R>;
@@ -102,12 +102,13 @@ template <op_id id, op_type ot, typename L, typename R> struct op_ {
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
if (id == op_truediv || id == op_itruediv) if (id == op_truediv || id == op_itruediv)
cl.def(id == op_itruediv ? "__idiv__" cl.def(id == op_itruediv ? "__idiv__"
: ot == op_l ? "__div__" : "__rdiv__", : ot == op_l ? "__div__"
: "__rdiv__",
&op::execute, is_operator(), extra...); &op::execute, is_operator(), extra...);
#endif #endif
} }
template <typename Class, typename... Extra> template <typename Class, typename... Extra>
void execute_cast(Class &cl, const Extra &... extra) const { void execute_cast(Class &cl, const Extra &...extra) const {
using Base = typename Class::type; using Base = typename Class::type;
using L_type = conditional_t<std::is_same<L, self_t>::value, Base, L>; using L_type = conditional_t<std::is_same<L, self_t>::value, Base, L>;
using R_type = conditional_t<std::is_same<R, self_t>::value, Base, R>; using R_type = conditional_t<std::is_same<R, self_t>::value, Base, R>;
@@ -116,7 +117,8 @@ template <op_id id, op_type ot, typename L, typename R> struct op_ {
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
if (id == op_truediv || id == op_itruediv) if (id == op_truediv || id == op_itruediv)
cl.def(id == op_itruediv ? "__idiv__" cl.def(id == op_itruediv ? "__idiv__"
: ot == op_l ? "__div__" : "__rdiv__", : ot == op_l ? "__div__"
: "__rdiv__",
&op::execute, is_operator(), extra...); &op::execute, is_operator(), extra...);
#endif #endif
} }
@@ -177,19 +179,19 @@ template <op_id id, op_type ot, typename L, typename R> struct op_ {
PYBIND11_BINARY_OPERATOR(sub, rsub, operator-, l - r) PYBIND11_BINARY_OPERATOR(sub, rsub, operator-, l - r)
PYBIND11_BINARY_OPERATOR(add, radd, operator+, l + r) PYBIND11_BINARY_OPERATOR(add, radd, operator+, l + r)
PYBIND11_BINARY_OPERATOR(mul, rmul, operator*, l * r) PYBIND11_BINARY_OPERATOR(mul, rmul, operator*, l *r)
PYBIND11_BINARY_OPERATOR(truediv, rtruediv, operator/, l / r) PYBIND11_BINARY_OPERATOR(truediv, rtruediv, operator/, l / r)
PYBIND11_BINARY_OPERATOR(mod, rmod, operator%, l % r) PYBIND11_BINARY_OPERATOR(mod, rmod, operator%, l % r)
PYBIND11_BINARY_OPERATOR(lshift, rlshift, operator<<, l << r) PYBIND11_BINARY_OPERATOR(lshift, rlshift, operator<<, l << r)
PYBIND11_BINARY_OPERATOR(rshift, rrshift, operator>>, l>> r) PYBIND11_BINARY_OPERATOR(rshift, rrshift, operator>>, l >> r)
PYBIND11_BINARY_OPERATOR(and, rand, operator&, l & r) PYBIND11_BINARY_OPERATOR(and, rand, operator&, l &r)
PYBIND11_BINARY_OPERATOR(xor, rxor, operator^, l ^ r) PYBIND11_BINARY_OPERATOR(xor, rxor, operator^, l ^ r)
PYBIND11_BINARY_OPERATOR(eq, eq, operator==, l == r) PYBIND11_BINARY_OPERATOR(eq, eq, operator==, l == r)
PYBIND11_BINARY_OPERATOR(ne, ne, operator!=, l != r) PYBIND11_BINARY_OPERATOR(ne, ne, operator!=, l != r)
PYBIND11_BINARY_OPERATOR(or, ror, operator|, l | r) PYBIND11_BINARY_OPERATOR(or, ror, operator|, l | r)
PYBIND11_BINARY_OPERATOR(gt, lt, operator>, l> r) PYBIND11_BINARY_OPERATOR(gt, lt, operator>, l > r)
PYBIND11_BINARY_OPERATOR(ge, le, operator>=, l >= r) PYBIND11_BINARY_OPERATOR(ge, le, operator>=, l >= r)
PYBIND11_BINARY_OPERATOR(lt, gt, operator<, l<r) PYBIND11_BINARY_OPERATOR(lt, gt, operator<, l < r)
PYBIND11_BINARY_OPERATOR(le, ge, operator<=, l <= r) PYBIND11_BINARY_OPERATOR(le, ge, operator<=, l <= r)
// PYBIND11_BINARY_OPERATOR(pow, rpow, pow, std::pow(l, // PYBIND11_BINARY_OPERATOR(pow, rpow, pow, std::pow(l,
// r)) // r))
@@ -203,11 +205,11 @@ PYBIND11_INPLACE_OPERATOR(irshift, operator>>=, l >>= r)
PYBIND11_INPLACE_OPERATOR(iand, operator&=, l &= r) PYBIND11_INPLACE_OPERATOR(iand, operator&=, l &= r)
PYBIND11_INPLACE_OPERATOR(ixor, operator^=, l ^= r) PYBIND11_INPLACE_OPERATOR(ixor, operator^=, l ^= r)
PYBIND11_INPLACE_OPERATOR(ior, operator|=, l |= r) PYBIND11_INPLACE_OPERATOR(ior, operator|=, l |= r)
PYBIND11_UNARY_OPERATOR(neg, operator-, - l) PYBIND11_UNARY_OPERATOR(neg, operator-, -l)
PYBIND11_UNARY_OPERATOR(pos, operator+, + l) PYBIND11_UNARY_OPERATOR(pos, operator+, +l)
PYBIND11_UNARY_OPERATOR(abs, abs, std::abs(l)) PYBIND11_UNARY_OPERATOR(abs, abs, std::abs(l))
PYBIND11_UNARY_OPERATOR(hash, hash, std::hash<L>()(l)) PYBIND11_UNARY_OPERATOR(hash, hash, std::hash<L>()(l))
PYBIND11_UNARY_OPERATOR(invert, operator~,(~l)) PYBIND11_UNARY_OPERATOR(invert, operator~, (~l))
PYBIND11_UNARY_OPERATOR(bool, operator!, !!l) PYBIND11_UNARY_OPERATOR(bool, operator!, !!l)
PYBIND11_UNARY_OPERATOR(int, int_, (int)l) PYBIND11_UNARY_OPERATOR(int, int_, (int)l)
PYBIND11_UNARY_OPERATOR(float, float_, (double)l) PYBIND11_UNARY_OPERATOR(float, float_, (double)l)

View File

@@ -74,7 +74,7 @@ public:
/// Construct a cpp_function from a vanilla function pointer /// Construct a cpp_function from a vanilla function pointer
template <typename Return, typename... Args, typename... Extra> template <typename Return, typename... Args, typename... Extra>
cpp_function(Return (*f)(Args...), const Extra &... extra) { cpp_function(Return (*f)(Args...), const Extra &...extra) {
initialize(f, f, extra...); initialize(f, f, extra...);
} }
@@ -82,14 +82,14 @@ public:
/// state) /// state)
template <typename Func, typename... Extra, template <typename Func, typename... Extra,
typename = detail::enable_if_t<detail::is_lambda<Func>::value>> typename = detail::enable_if_t<detail::is_lambda<Func>::value>>
cpp_function(Func &&f, const Extra &... extra) { cpp_function(Func &&f, const Extra &...extra) {
initialize(std::forward<Func>(f), initialize(std::forward<Func>(f),
(detail::function_signature_t<Func> *)nullptr, extra...); (detail::function_signature_t<Func> *)nullptr, extra...);
} }
/// Construct a cpp_function from a class method (non-const) /// Construct a cpp_function from a class method (non-const)
template <typename Return, typename Class, typename... Arg, typename... Extra> template <typename Return, typename Class, typename... Arg, typename... Extra>
cpp_function(Return (Class::*f)(Arg...), const Extra &... extra) { cpp_function(Return (Class::*f)(Arg...), const Extra &...extra) {
initialize( initialize(
[f](Class *c, Arg... args) -> Return { return (c->*f)(args...); }, [f](Class *c, Arg... args) -> Return { return (c->*f)(args...); },
(Return(*)(Class *, Arg...)) nullptr, extra...); (Return(*)(Class *, Arg...)) nullptr, extra...);
@@ -97,7 +97,7 @@ public:
/// Construct a cpp_function from a class method (const) /// Construct a cpp_function from a class method (const)
template <typename Return, typename Class, typename... Arg, typename... Extra> template <typename Return, typename Class, typename... Arg, typename... Extra>
cpp_function(Return (Class::*f)(Arg...) const, const Extra &... extra) { cpp_function(Return (Class::*f)(Arg...) const, const Extra &...extra) {
initialize( initialize(
[f](const Class *c, Arg... args) -> Return { return (c->*f)(args...); }, [f](const Class *c, Arg... args) -> Return { return (c->*f)(args...); },
(Return(*)(const Class *, Arg...)) nullptr, extra...); (Return(*)(const Class *, Arg...)) nullptr, extra...);
@@ -114,7 +114,7 @@ protected:
/// Special internal constructor for functors, lambda functions, etc. /// Special internal constructor for functors, lambda functions, etc.
template <typename Func, typename Return, typename... Args, typename... Extra> template <typename Func, typename Return, typename... Args, typename... Extra>
void initialize(Func &&f, Return (*)(Args...), const Extra &... extra) { void initialize(Func &&f, Return (*)(Args...), const Extra &...extra) {
using namespace detail; using namespace detail;
struct capture { struct capture {
remove_reference_t<Func> f; remove_reference_t<Func> f;
@@ -924,7 +924,7 @@ public:
details on the ``Extra&& ... extra`` argument, see section :ref:`extras`. details on the ``Extra&& ... extra`` argument, see section :ref:`extras`.
\endrst */ \endrst */
template <typename Func, typename... Extra> template <typename Func, typename... Extra>
module &def(const char *name_, Func &&f, const Extra &... extra) { module &def(const char *name_, Func &&f, const Extra &...extra) {
cpp_function func(std::forward<Func>(f), name(name_), scope(*this), cpp_function func(std::forward<Func>(f), name(name_), scope(*this),
sibling(getattr(*this, name_, none())), extra...); sibling(getattr(*this, name_, none())), extra...);
// NB: allow overwriting here because cpp_function sets up a chain with the // NB: allow overwriting here because cpp_function sets up a chain with the
@@ -1104,8 +1104,8 @@ protected:
/// Set the pointer to operator new if it exists. The cast is needed because it /// Set the pointer to operator new if it exists. The cast is needed because it
/// can be overloaded. /// can be overloaded.
template <typename T, typename = void_t<decltype( template <typename T, typename = void_t<decltype(static_cast<void *(*)(size_t)>(
static_cast<void *(*)(size_t)>(T::operator new))>> T::operator new))>>
void set_operator_new(type_record *r) { void set_operator_new(type_record *r) {
r->operator_new = &T::operator new; r->operator_new = &T::operator new;
} }
@@ -1204,7 +1204,7 @@ public:
PYBIND11_OBJECT(class_, generic_type, PyType_Check) PYBIND11_OBJECT(class_, generic_type, PyType_Check)
template <typename... Extra> template <typename... Extra>
class_(handle scope, const char *name, const Extra &... extra) { class_(handle scope, const char *name, const Extra &...extra) {
using namespace detail; using namespace detail;
// MI can only be specified via class_ template options, not constructor // MI can only be specified via class_ template options, not constructor
@@ -1263,7 +1263,7 @@ public:
static void add_base(detail::type_record &) {} static void add_base(detail::type_record &) {}
template <typename Func, typename... Extra> template <typename Func, typename... Extra>
class_ &def(const char *name_, Func &&f, const Extra &... extra) { class_ &def(const char *name_, Func &&f, const Extra &...extra) {
cpp_function cf(method_adaptor<type>(std::forward<Func>(f)), name(name_), cpp_function cf(method_adaptor<type>(std::forward<Func>(f)), name(name_),
is_method(*this), sibling(getattr(*this, name_, none())), is_method(*this), sibling(getattr(*this, name_, none())),
extra...); extra...);
@@ -1272,7 +1272,7 @@ public:
} }
template <typename Func, typename... Extra> template <typename Func, typename... Extra>
class_ &def_static(const char *name_, Func &&f, const Extra &... extra) { class_ &def_static(const char *name_, Func &&f, const Extra &...extra) {
static_assert( static_assert(
!std::is_member_function_pointer<Func>::value, !std::is_member_function_pointer<Func>::value,
"def_static(...) called with a non-static member function pointer"); "def_static(...) called with a non-static member function pointer");
@@ -1284,43 +1284,42 @@ public:
template <detail::op_id id, detail::op_type ot, typename L, typename R, template <detail::op_id id, detail::op_type ot, typename L, typename R,
typename... Extra> typename... Extra>
class_ &def(const detail::op_<id, ot, L, R> &op, const Extra &... extra) { class_ &def(const detail::op_<id, ot, L, R> &op, const Extra &...extra) {
op.execute(*this, extra...); op.execute(*this, extra...);
return *this; return *this;
} }
template <detail::op_id id, detail::op_type ot, typename L, typename R, template <detail::op_id id, detail::op_type ot, typename L, typename R,
typename... Extra> typename... Extra>
class_ &def_cast(const detail::op_<id, ot, L, R> &op, class_ &def_cast(const detail::op_<id, ot, L, R> &op, const Extra &...extra) {
const Extra &... extra) {
op.execute_cast(*this, extra...); op.execute_cast(*this, extra...);
return *this; return *this;
} }
template <typename... Args, typename... Extra> template <typename... Args, typename... Extra>
class_ &def(const detail::initimpl::constructor<Args...> &init, class_ &def(const detail::initimpl::constructor<Args...> &init,
const Extra &... extra) { const Extra &...extra) {
init.execute(*this, extra...); init.execute(*this, extra...);
return *this; return *this;
} }
template <typename... Args, typename... Extra> template <typename... Args, typename... Extra>
class_ &def(const detail::initimpl::alias_constructor<Args...> &init, class_ &def(const detail::initimpl::alias_constructor<Args...> &init,
const Extra &... extra) { const Extra &...extra) {
init.execute(*this, extra...); init.execute(*this, extra...);
return *this; return *this;
} }
template <typename... Args, typename... Extra> template <typename... Args, typename... Extra>
class_ &def(detail::initimpl::factory<Args...> &&init, class_ &def(detail::initimpl::factory<Args...> &&init,
const Extra &... extra) { const Extra &...extra) {
std::move(init).execute(*this, extra...); std::move(init).execute(*this, extra...);
return *this; return *this;
} }
template <typename... Args, typename... Extra> template <typename... Args, typename... Extra>
class_ &def(detail::initimpl::pickle_factory<Args...> &&pf, class_ &def(detail::initimpl::pickle_factory<Args...> &&pf,
const Extra &... extra) { const Extra &...extra) {
std::move(pf).execute(*this, extra...); std::move(pf).execute(*this, extra...);
return *this; return *this;
} }
@@ -1352,7 +1351,7 @@ public:
} }
template <typename C, typename D, typename... Extra> template <typename C, typename D, typename... Extra>
class_ &def_readwrite(const char *name, D C::*pm, const Extra &... extra) { class_ &def_readwrite(const char *name, D C::*pm, const Extra &...extra) {
static_assert( static_assert(
std::is_same<C, type>::value || std::is_base_of<C, type>::value, std::is_same<C, type>::value || std::is_base_of<C, type>::value,
"def_readwrite() requires a class member (or base class member)"); "def_readwrite() requires a class member (or base class member)");
@@ -1367,7 +1366,7 @@ public:
template <typename C, typename D, typename... Extra> template <typename C, typename D, typename... Extra>
class_ &def_readonly(const char *name, const D C::*pm, class_ &def_readonly(const char *name, const D C::*pm,
const Extra &... extra) { const Extra &...extra) {
static_assert( static_assert(
std::is_same<C, type>::value || std::is_base_of<C, type>::value, std::is_same<C, type>::value || std::is_base_of<C, type>::value,
"def_readonly() requires a class member (or base class member)"); "def_readonly() requires a class member (or base class member)");
@@ -1379,8 +1378,7 @@ public:
} }
template <typename D, typename... Extra> template <typename D, typename... Extra>
class_ &def_readwrite_static(const char *name, D *pm, class_ &def_readwrite_static(const char *name, D *pm, const Extra &...extra) {
const Extra &... extra) {
cpp_function fget([pm](object) -> const D & { return *pm; }, scope(*this)), cpp_function fget([pm](object) -> const D & { return *pm; }, scope(*this)),
fset([pm](object, const D &value) { *pm = value; }, scope(*this)); fset([pm](object, const D &value) { *pm = value; }, scope(*this));
def_property_static(name, fget, fset, return_value_policy::reference, def_property_static(name, fget, fset, return_value_policy::reference,
@@ -1390,7 +1388,7 @@ public:
template <typename D, typename... Extra> template <typename D, typename... Extra>
class_ &def_readonly_static(const char *name, const D *pm, class_ &def_readonly_static(const char *name, const D *pm,
const Extra &... extra) { const Extra &...extra) {
cpp_function fget([pm](object) -> const D & { return *pm; }, scope(*this)); cpp_function fget([pm](object) -> const D & { return *pm; }, scope(*this));
def_property_readonly_static(name, fget, return_value_policy::reference, def_property_readonly_static(name, fget, return_value_policy::reference,
extra...); extra...);
@@ -1400,7 +1398,7 @@ public:
/// Uses return_value_policy::reference_internal by default /// Uses return_value_policy::reference_internal by default
template <typename Getter, typename... Extra> template <typename Getter, typename... Extra>
class_ &def_property_readonly(const char *name, const Getter &fget, class_ &def_property_readonly(const char *name, const Getter &fget,
const Extra &... extra) { const Extra &...extra) {
return def_property_readonly(name, cpp_function(method_adaptor<type>(fget)), return def_property_readonly(name, cpp_function(method_adaptor<type>(fget)),
return_value_policy::reference_internal, return_value_policy::reference_internal,
extra...); extra...);
@@ -1409,14 +1407,14 @@ public:
/// Uses cpp_function's return_value_policy by default /// Uses cpp_function's return_value_policy by default
template <typename... Extra> template <typename... Extra>
class_ &def_property_readonly(const char *name, const cpp_function &fget, class_ &def_property_readonly(const char *name, const cpp_function &fget,
const Extra &... extra) { const Extra &...extra) {
return def_property(name, fget, nullptr, extra...); return def_property(name, fget, nullptr, extra...);
} }
/// Uses return_value_policy::reference by default /// Uses return_value_policy::reference by default
template <typename Getter, typename... Extra> template <typename Getter, typename... Extra>
class_ &def_property_readonly_static(const char *name, const Getter &fget, class_ &def_property_readonly_static(const char *name, const Getter &fget,
const Extra &... extra) { const Extra &...extra) {
return def_property_readonly_static( return def_property_readonly_static(
name, cpp_function(fget), return_value_policy::reference, extra...); name, cpp_function(fget), return_value_policy::reference, extra...);
} }
@@ -1425,20 +1423,20 @@ public:
template <typename... Extra> template <typename... Extra>
class_ &def_property_readonly_static(const char *name, class_ &def_property_readonly_static(const char *name,
const cpp_function &fget, const cpp_function &fget,
const Extra &... extra) { const Extra &...extra) {
return def_property_static(name, fget, nullptr, extra...); return def_property_static(name, fget, nullptr, extra...);
} }
/// Uses return_value_policy::reference_internal by default /// Uses return_value_policy::reference_internal by default
template <typename Getter, typename Setter, typename... Extra> template <typename Getter, typename Setter, typename... Extra>
class_ &def_property(const char *name, const Getter &fget, const Setter &fset, class_ &def_property(const char *name, const Getter &fget, const Setter &fset,
const Extra &... extra) { const Extra &...extra) {
return def_property(name, fget, cpp_function(method_adaptor<type>(fset)), return def_property(name, fget, cpp_function(method_adaptor<type>(fset)),
extra...); extra...);
} }
template <typename Getter, typename... Extra> template <typename Getter, typename... Extra>
class_ &def_property(const char *name, const Getter &fget, class_ &def_property(const char *name, const Getter &fget,
const cpp_function &fset, const Extra &... extra) { const cpp_function &fset, const Extra &...extra) {
return def_property(name, cpp_function(method_adaptor<type>(fget)), fset, return def_property(name, cpp_function(method_adaptor<type>(fget)), fset,
return_value_policy::reference_internal, extra...); return_value_policy::reference_internal, extra...);
} }
@@ -1446,15 +1444,14 @@ public:
/// Uses cpp_function's return_value_policy by default /// Uses cpp_function's return_value_policy by default
template <typename... Extra> template <typename... Extra>
class_ &def_property(const char *name, const cpp_function &fget, class_ &def_property(const char *name, const cpp_function &fget,
const cpp_function &fset, const Extra &... extra) { const cpp_function &fset, const Extra &...extra) {
return def_property_static(name, fget, fset, is_method(*this), extra...); return def_property_static(name, fget, fset, is_method(*this), extra...);
} }
/// Uses return_value_policy::reference by default /// Uses return_value_policy::reference by default
template <typename Getter, typename... Extra> template <typename Getter, typename... Extra>
class_ &def_property_static(const char *name, const Getter &fget, class_ &def_property_static(const char *name, const Getter &fget,
const cpp_function &fset, const cpp_function &fset, const Extra &...extra) {
const Extra &... extra) {
return def_property_static(name, cpp_function(fget), fset, return def_property_static(name, cpp_function(fget), fset,
return_value_policy::reference, extra...); return_value_policy::reference, extra...);
} }
@@ -1462,8 +1459,7 @@ public:
/// Uses cpp_function's return_value_policy by default /// Uses cpp_function's return_value_policy by default
template <typename... Extra> template <typename... Extra>
class_ &def_property_static(const char *name, const cpp_function &fget, class_ &def_property_static(const char *name, const cpp_function &fget,
const cpp_function &fset, const cpp_function &fset, const Extra &...extra) {
const Extra &... extra) {
static_assert( static_assert(
0 == detail::constexpr_sum(std::is_base_of<arg, Extra>::value...), 0 == detail::constexpr_sum(std::is_base_of<arg, Extra>::value...),
"Argument annotations are not allowed for properties"); "Argument annotations are not allowed for properties");
@@ -1782,7 +1778,7 @@ public:
using Scalar = typename std::underlying_type<Type>::type; using Scalar = typename std::underlying_type<Type>::type;
template <typename... Extra> template <typename... Extra>
enum_(const handle &scope, const char *name, const Extra &... extra) enum_(const handle &scope, const char *name, const Extra &...extra)
: class_<Type>(scope, name, extra...), m_base(*this, scope) { : class_<Type>(scope, name, extra...), m_base(*this, scope) {
constexpr bool is_arithmetic = constexpr bool is_arithmetic =
detail::any_of<std::is_same<arithmetic, Extra>...>::value; detail::any_of<std::is_same<arithmetic, Extra>...>::value;
@@ -1898,7 +1894,7 @@ template <return_value_policy Policy = return_value_policy::reference_internal,
typename Iterator, typename Sentinel, typename Iterator, typename Sentinel,
typename ValueType = decltype(*std::declval<Iterator>()), typename ValueType = decltype(*std::declval<Iterator>()),
typename... Extra> typename... Extra>
iterator make_iterator(Iterator first, Sentinel last, Extra &&... extra) { iterator make_iterator(Iterator first, Sentinel last, Extra &&...extra) {
typedef detail::iterator_state<Iterator, Sentinel, false, Policy> state; typedef detail::iterator_state<Iterator, Sentinel, false, Policy> state;
if (!detail::get_type_info(typeid(state), false)) { if (!detail::get_type_info(typeid(state), false)) {
@@ -1929,7 +1925,7 @@ template <return_value_policy Policy = return_value_policy::reference_internal,
typename Iterator, typename Sentinel, typename Iterator, typename Sentinel,
typename KeyType = decltype((*std::declval<Iterator>()).first), typename KeyType = decltype((*std::declval<Iterator>()).first),
typename... Extra> typename... Extra>
iterator make_key_iterator(Iterator first, Sentinel last, Extra &&... extra) { iterator make_key_iterator(Iterator first, Sentinel last, Extra &&...extra) {
typedef detail::iterator_state<Iterator, Sentinel, true, Policy> state; typedef detail::iterator_state<Iterator, Sentinel, true, Policy> state;
if (!detail::get_type_info(typeid(state), false)) { if (!detail::get_type_info(typeid(state), false)) {
@@ -1958,7 +1954,7 @@ iterator make_key_iterator(Iterator first, Sentinel last, Extra &&... extra) {
/// supporting `std::begin()`/`std::end()` /// supporting `std::begin()`/`std::end()`
template <return_value_policy Policy = return_value_policy::reference_internal, template <return_value_policy Policy = return_value_policy::reference_internal,
typename Type, typename... Extra> typename Type, typename... Extra>
iterator make_iterator(Type &value, Extra &&... extra) { iterator make_iterator(Type &value, Extra &&...extra) {
return make_iterator<Policy>(std::begin(value), std::end(value), extra...); return make_iterator<Policy>(std::begin(value), std::end(value), extra...);
} }
@@ -1966,7 +1962,7 @@ iterator make_iterator(Type &value, Extra &&... extra) {
/// supporting `std::begin()`/`std::end()` /// supporting `std::begin()`/`std::end()`
template <return_value_policy Policy = return_value_policy::reference_internal, template <return_value_policy Policy = return_value_policy::reference_internal,
typename Type, typename... Extra> typename Type, typename... Extra>
iterator make_key_iterator(Type &value, Extra &&... extra) { iterator make_key_iterator(Type &value, Extra &&...extra) {
return make_key_iterator<Policy>(std::begin(value), std::end(value), return make_key_iterator<Policy>(std::begin(value), std::end(value),
extra...); extra...);
} }
@@ -2106,7 +2102,7 @@ NAMESPACE_END(detail)
template <return_value_policy policy = return_value_policy::automatic_reference, template <return_value_policy policy = return_value_policy::automatic_reference,
typename... Args> typename... Args>
void print(Args &&... args) { void print(Args &&...args) {
auto c = detail::collect_arguments<policy>(std::forward<Args>(args)...); auto c = detail::collect_arguments<policy>(std::forward<Args>(args)...);
detail::print(c.args(), c.kwargs()); detail::print(c.args(), c.kwargs());
} }

View File

@@ -112,12 +112,12 @@ public:
template < template <
return_value_policy policy = return_value_policy::automatic_reference, return_value_policy policy = return_value_policy::automatic_reference,
typename... Args> typename... Args>
object operator()(Args &&... args) const; object operator()(Args &&...args) const;
template < template <
return_value_policy policy = return_value_policy::automatic_reference, return_value_policy policy = return_value_policy::automatic_reference,
typename... Args> typename... Args>
PYBIND11_DEPRECATED("call(...) was deprecated in favor of operator()(...)") PYBIND11_DEPRECATED("call(...) was deprecated in favor of operator()(...)")
object call(Args &&... args) const; object call(Args &&...args) const;
/// Equivalent to ``obj is other`` in Python. /// Equivalent to ``obj is other`` in Python.
bool is(object_api const &other) const { bool is(object_api const &other) const {
@@ -1109,7 +1109,7 @@ public:
return std::string(buffer, (size_t)length); return std::string(buffer, (size_t)length);
} }
template <typename... Args> str format(Args &&... args) const { template <typename... Args> str format(Args &&...args) const {
return attr("format")(std::forward<Args>(args)...); return attr("format")(std::forward<Args>(args)...);
} }
@@ -1282,11 +1282,9 @@ public:
template <typename T, template <typename T,
detail::enable_if_t<std::is_integral<T>::value, int> = 0> detail::enable_if_t<std::is_integral<T>::value, int> = 0>
operator T() const { operator T() const {
return std::is_unsigned<T>::value return std::is_unsigned<T>::value ? detail::as_unsigned<T>(m_ptr)
? detail::as_unsigned<T>(m_ptr) : sizeof(T) <= sizeof(long) ? (T)PyLong_AsLong(m_ptr)
: sizeof(T) <= sizeof(long) : (T)PYBIND11_LONG_AS_LONGLONG(m_ptr);
? (T)PyLong_AsLong(m_ptr)
: (T)PYBIND11_LONG_AS_LONGLONG(m_ptr);
} }
}; };
@@ -1438,7 +1436,7 @@ public:
// defer the collector // defer the collector
typename collector = typename collector =
detail::deferred_t<detail::unpacking_collector<>, Args...>> detail::deferred_t<detail::unpacking_collector<>, Args...>>
explicit dict(Args &&... args) explicit dict(Args &&...args)
: dict(collector(std::forward<Args>(args)...).kwargs()) {} : dict(collector(std::forward<Args>(args)...).kwargs()) {}
size_t size() const { return (size_t)PyDict_Size(m_ptr); } size_t size() const { return (size_t)PyDict_Size(m_ptr); }

View File

@@ -356,7 +356,7 @@ struct variant_caster_visitor {
/// `boost::variant` and `boost::apply_visitor`. /// `boost::variant` and `boost::apply_visitor`.
template <template <typename...> class Variant> struct visit_helper { template <template <typename...> class Variant> struct visit_helper {
template <typename... Args> template <typename... Args>
static auto call(Args &&... args) static auto call(Args &&...args)
-> decltype(visit(std::forward<Args>(args)...)) { -> decltype(visit(std::forward<Args>(args)...)) {
return visit(std::forward<Args>(args)...); return visit(std::forward<Args>(args)...);
} }

View File

@@ -432,7 +432,7 @@ NAMESPACE_END(detail)
template <typename Vector, typename holder_type = std::unique_ptr<Vector>, template <typename Vector, typename holder_type = std::unique_ptr<Vector>,
typename... Args> typename... Args>
class_<Vector, holder_type> bind_vector(handle scope, std::string const &name, class_<Vector, holder_type> bind_vector(handle scope, std::string const &name,
Args &&... args) { Args &&...args) {
using Class_ = class_<Vector, holder_type>; using Class_ = class_<Vector, holder_type>;
// If the value_type is unregistered (e.g. a converting type) or is itself // If the value_type is unregistered (e.g. a converting type) or is itself
@@ -596,7 +596,7 @@ NAMESPACE_END(detail)
template <typename Map, typename holder_type = std::unique_ptr<Map>, template <typename Map, typename holder_type = std::unique_ptr<Map>,
typename... Args> typename... Args>
class_<Map, holder_type> bind_map(handle scope, const std::string &name, class_<Map, holder_type> bind_map(handle scope, const std::string &name,
Args &&... args) { Args &&...args) {
using KeyType = typename Map::key_type; using KeyType = typename Map::key_type;
using MappedType = typename Map::mapped_type; using MappedType = typename Map::mapped_type;
using Class_ = class_<Map, holder_type>; using Class_ = class_<Map, holder_type>;