20 #include <unordered_map> 21 #include <unordered_set> 25 #if defined(PYBIND11_HAS_OPTIONAL) 27 #elif defined(PYBIND11_HAS_EXP_OPTIONAL) 28 # include <experimental/optional> 31 #if defined(PYBIND11_HAS_VARIANT) 38 template <
typename T,
typename U>
47 template <
typename T,
typename U>
49 return std::forward<detail::forwarded_type<T, U>>(std::forward<U>(u));
52 template <
typename Type,
typename Key>
58 if (!isinstance<anyset>(src)) {
61 auto s = reinterpret_borrow<anyset>(src);
63 for (
auto entry :
s) {
65 if (!conv.
load(entry, convert)) {
68 value.insert(cast_op<Key &&>(std::move(conv)));
79 for (
auto &&
value : src) {
80 auto value_ = reinterpret_steal<object>(
82 if (!value_ || !s.add(std::move(value_))) {
92 template <
typename Type,
typename Key,
typename Value>
98 if (!isinstance<dict>(src)) {
101 auto d = reinterpret_borrow<dict>(src);
109 value.emplace(cast_op<Key &&>(std::move(kconv)), cast_op<Value &&>(std::move(vconv)));
114 template <
typename T>
123 for (
auto &&kv : src) {
124 auto key = reinterpret_steal<object>(
126 auto value = reinterpret_steal<object>(
128 if (!
key || !value) {
131 d[std::move(
key)] = std::move(value);
141 template <
typename Type,
typename Value>
146 if (!isinstance<sequence>(src) || isinstance<bytes>(src) || isinstance<str>(src)) {
149 auto s = reinterpret_borrow<sequence>(src);
154 if (!conv.
load(it, convert)) {
157 value.push_back(cast_op<Value &&>(std::move(conv)));
172 template <
typename T>
179 for (
auto &&
value : src) {
180 auto value_ = reinterpret_steal<object>(
185 PyList_SET_ITEM(
l.ptr(), index++, value_.release().ptr());
193 template <
typename Type,
typename Alloc>
196 template <
typename Type,
typename Alloc>
199 template <
typename Type,
typename Alloc>
202 template <
typename ArrayType,
typename Value,
bool Resizable,
size_t Size = 0>
207 template <
bool R = Resizable>
214 template <
bool R = Resizable>
221 if (!isinstance<sequence>(src)) {
224 auto l = reinterpret_borrow<sequence>(src);
225 if (!require_size(
l.size())) {
231 if (!conv.
load(it, convert)) {
234 value[ctr++] = cast_op<Value &&>(std::move(conv));
239 template <
typename T>
243 for (
auto &&
value : src) {
244 auto value_ = reinterpret_steal<object>(
249 PyList_SET_ITEM(
l.ptr(), index++, value_.release().ptr());
262 template <
typename Type,
size_t Size>
264 :
array_caster<std::array<Type, Size>, Type, false, Size> {};
266 template <
typename Type>
269 template <
typename Key,
typename Compare,
typename Alloc>
271 :
set_caster<std::set<Key, Compare, Alloc>, Key> {};
273 template <
typename Key,
typename Hash,
typename Equal,
typename Alloc>
275 :
set_caster<std::unordered_set<Key, Hash, Equal, Alloc>, Key> {};
277 template <
typename Key,
typename Value,
typename Compare,
typename Alloc>
279 :
map_caster<std::map<Key, Value, Compare, Alloc>, Key, Value> {};
281 template <
typename Key,
typename Value,
typename Hash,
typename Equal,
typename Alloc>
282 struct type_caster<std::unordered_map<Key, Value, Hash, Equal, Alloc>>
283 :
map_caster<std::unordered_map<Key, Value, Hash, Equal, Alloc>, Key, Value> {};
286 template <
typename Type,
typename Value =
typename Type::value_type>
290 template <
typename T>
309 if (!inner_caster.
load(src, convert)) {
313 value.emplace(cast_op<Value &&>(std::move(inner_caster)));
320 #if defined(PYBIND11_HAS_OPTIONAL) 321 template <
typename T>
328 #if defined(PYBIND11_HAS_EXP_OPTIONAL) 329 template <
typename T>
335 :
public void_caster<std::experimental::nullopt_t> {};
345 template <
typename T>
355 template <
template <
typename...>
class Variant>
357 template <
typename... Args>
358 static auto call(Args &&...
args) -> decltype(visit(std::forward<Args>(
args)...)) {
359 return visit(std::forward<Args>(
args)...);
364 template <
typename Variant>
367 template <
template <
typename...>
class V,
typename... Ts>
369 static_assert(
sizeof...(Ts) > 0,
"Variant must consist of at least one alternative.");
371 template <
typename U,
typename... Us>
374 if (caster.load(src, convert)) {
375 value = cast_op<U>(std::move(caster));
394 template <
typename Variant>
397 std::forward<Variant>(src));
406 #if defined(PYBIND11_HAS_VARIANT) 407 template <
typename... Ts>
416 inline std::ostream &operator<<(std::ostream &
os, const
handle &obj) {
417 #ifdef PYBIND11_HAS_STRING_VIEW 418 os <<
str(obj).cast<std::string_view>();
420 os << (std::string)
str(obj);
typename std::conditional< B, T, F >::type conditional_t
const gtsam::Symbol key('X', 0)
Helper template which holds a list of types.
void reserve_maybe(const sequence &, void *)
PyObject * conv(PyObject *o)
bool load(handle src, bool convert)
bool load(handle src, bool convert)
result_type operator()(T &&src) const
bool load(handle src, bool convert)
void reserve_maybe(const sequence &s, Type *)
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 require_size(enable_if_t< R, size_t > size)
static handle cast(T &&src, return_value_policy policy, handle parent)
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)
static handle cast(T &&src, return_value_policy policy, handle parent)
conditional_t< std::is_lvalue_reference< T >::value, remove_reference_t< U > &, remove_reference_t< U > && > forwarded_type
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)
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)
constexpr descr< N - 1 > const_name(char const (&text)[N])
bool load(handle src, bool convert)
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
PYBIND11_TYPE_CASTER(type, const_name("Set[")+key_conv::name+const_name("]"))
Visit a variant and cast any found type to Python.
#define PYBIND11_NAMESPACE_END(name)
static BinaryMeasurement< Rot3 > convert(const BetweenFactor< Pose3 >::shared_ptr &f)
static handle cast(T &&src, return_value_policy policy, handle parent)
#define PYBIND11_NAMESPACE_BEGIN(name)