14 #include <unordered_set> 16 #include <unordered_map> 24 #pragma warning(disable: 4127) // warning C4127: Conditional expression is constant 29 # if defined(PYBIND11_CPP17) && __has_include(<optional>) 31 # define PYBIND11_HAS_OPTIONAL 1 34 # if defined(PYBIND11_CPP14) && (__has_include(<experimental/optional>) && \ 35 !__has_include(<optional>)) 36 # include <experimental/optional> 37 # define PYBIND11_HAS_EXP_OPTIONAL 1 40 # if defined(PYBIND11_CPP17) && __has_include(<variant>) 42 # define PYBIND11_HAS_VARIANT 1 44 #elif defined(_MSC_VER) && defined(PYBIND11_CPP17) 47 # define PYBIND11_HAS_OPTIONAL 1 48 # define PYBIND11_HAS_VARIANT 1 56 template <typename
T, typename
U>
62 template <typename T, typename U>
64 return std::forward<detail::forwarded_type<T, U>>(std::forward<U>(u));
67 template <
typename Type,
typename Key>
struct set_caster {
72 if (!isinstance<pybind11::set>(src))
74 auto s = reinterpret_borrow<pybind11::set>(src);
76 for (
auto entry :
s) {
78 if (!conv.
load(entry, convert))
80 value.insert(cast_op<Key &&>(std::move(conv)));
90 for (
auto &&
value : src) {
91 auto value_ = reinterpret_steal<object>(
key_conv::cast(forward_like<T>(
value), policy, parent));
92 if (!value_ || !s.add(value_))
101 template <
typename Type,
typename Key,
typename Value>
struct map_caster {
106 if (!isinstance<dict>(src))
108 auto d = reinterpret_borrow<dict>(src);
116 value.emplace(cast_op<Key &&>(std::move(kconv)), cast_op<Value &&>(std::move(vconv)));
121 template <
typename T>
130 for (
auto &&kv : src) {
131 auto key = reinterpret_steal<object>(
key_conv::cast(forward_like<T>(kv.first), policy_key, parent));
132 auto value = reinterpret_steal<object>(
value_conv::cast(forward_like<T>(kv.second), policy_value, parent));
147 if (!isinstance<sequence>(src) || isinstance<str>(src))
149 auto s = reinterpret_borrow<sequence>(src);
154 if (!conv.
load(it, convert))
156 value.push_back(cast_op<Value &&>(std::move(conv)));
162 template <
typename T =
Type,
168 template <
typename T>
174 for (
auto &&
value : src) {
178 PyList_SET_ITEM(
l.ptr(), (
ssize_t) index++, value_.release().ptr());
189 template <
typename Type,
typename Alloc>
struct type_caster<
std::deque<Type, Alloc>>
195 template <
typename ArrayType,
typename Value,
bool Resizable,
size_t Size = 0>
struct array_caster {
199 template <
bool R = Resizable>
205 template <
bool R = Resizable>
212 if (!isinstance<sequence>(src))
214 auto l = reinterpret_borrow<sequence>(src);
215 if (!require_size(
l.size()))
220 if (!conv.
load(it, convert))
222 value[ctr++] = cast_op<Value &&>(std::move(conv));
227 template <
typename T>
231 for (
auto &&
value : src) {
235 PyList_SET_ITEM(
l.ptr(), (
ssize_t) index++, value_.release().ptr());
244 :
array_caster<std::array<Type, Size>, Type, false, Size> { };
249 template <
typename Key,
typename Compare,
typename Alloc>
struct type_caster<std::
set<Key, Compare, Alloc>>
250 :
set_caster<std::set<Key, Compare, Alloc>, Key> { };
252 template <
typename Key,
typename Hash,
typename Equal,
typename Alloc>
struct type_caster<std::unordered_set<Key, Hash, Equal, Alloc>>
253 :
set_caster<std::unordered_set<Key, Hash, Equal, Alloc>, Key> { };
255 template <
typename Key,
typename Value,
typename Compare,
typename Alloc>
struct type_caster<std::map<Key, Value, Compare, Alloc>>
256 :
map_caster<std::map<Key, Value, Compare, Alloc>, Key, Value> { };
258 template <
typename Key,
typename Value,
typename Hash,
typename Equal,
typename Alloc>
struct type_caster<std::unordered_map<Key, Value, Hash, Equal, Alloc>>
259 :
map_caster<std::unordered_map<Key, Value, Hash, Equal, Alloc>, Key, Value> { };
265 template <
typename T_>
278 }
else if (src.is_none()) {
282 if (!inner_caster.
load(src, convert))
285 value.emplace(cast_op<typename T::value_type &&>(std::move(inner_caster)));
292 #if defined(PYBIND11_HAS_OPTIONAL) 293 template<
typename T>
struct type_caster<std::optional<T>>
300 #if defined(PYBIND11_HAS_EXP_OPTIONAL) 301 template<
typename T>
struct type_caster<std::experimental::optional<T>>
304 template<>
struct type_caster<std::experimental::nullopt_t>
305 :
public void_caster<std::experimental::nullopt_t> {};
315 template <
typename T>
325 template <
template<
typename...>
class Variant>
327 template <
typename... Args>
328 static auto call(Args &&...
args) -> decltype(visit(std::forward<Args>(
args)...)) {
329 return visit(std::forward<Args>(
args)...);
336 template <
template<
typename...>
class V,
typename... Ts>
338 static_assert(
sizeof...(Ts) > 0,
"Variant must consist of at least one alternative.");
340 template <
typename U,
typename... Us>
343 if (caster.load(src, convert)) {
344 value = cast_op<U>(caster);
362 template <
typename Variant>
365 std::forward<Variant>(src));
372 #if defined(PYBIND11_HAS_VARIANT) 373 template <
typename... Ts>
379 inline std::ostream &operator<<(std::ostream &
os, const
handle &obj) {
380 os << (std::string)
str(obj);
386 #if defined(_MSC_VER) typename std::conditional< B, T, F >::type conditional_t
Helper template which holds a list of types.
void reserve_maybe(sequence, void *)
static handle cast(T_ &&src, return_value_policy policy, handle parent)
result_type operator()(T &&src) const
bool load(handle src, bool convert)
bool load(handle src, bool convert)
void reserve_maybe(sequence s, Type *)
bool load(handle src, bool convert)
bool load_alternative(handle, bool, type_list<>)
#define PYBIND11_NAMESPACE
const handle & inc_ref() const &
bool load(handle src, bool convert)
static handle cast(T &&src, return_value_policy policy, handle parent)
static const Line3 l(Rot3(), 1, 1)
static handle cast(const itype &src, return_value_policy policy, handle parent)
return_value_policy policy
bool load(handle src, bool convert)
bool require_size(enable_if_t< R, size_t > size)
conditional_t< std::is_lvalue_reference< T >::value, remove_reference_t< U > &, remove_reference_t< U > && > forwarded_type
static handle cast(T &&src, return_value_policy policy, handle parent)
bool convert(const int &y)
EIGEN_DEVICE_FUNC NewType cast(const OldType &x)
static return_value_policy policy(return_value_policy p)
typename std::remove_reference< T >::type remove_reference_t
constexpr descr< 0 > concat()
void set(Container &c, Position position, const Value &value)
bool require_size(enable_if_t<!R, size_t > size)
static auto call(Args &&...args) -> decltype(visit(std::forward< Args >(args)...))
ofstream os("timeSchurFactors.csv")
static handle cast(T &&src, return_value_policy policy, handle parent)
bool load(handle src, bool convert)
PYBIND11_TYPE_CASTER(type, _("Set[")+key_conv::name+_("]"))
bool load_alternative(handle src, bool convert, type_list< U, Us... >)
bool load(handle src, bool convert)
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
static constexpr auto name
forwarded_type< T, U > forward_like(U &&u)
static handle cast(Variant &&src, return_value_policy policy, handle parent)
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
Visit a variant and cast any found type to Python.
#define PYBIND11_NAMESPACE_END(name)
static handle cast(T &&src, return_value_policy policy, handle parent)
#define PYBIND11_NAMESPACE_BEGIN(name)