ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
pybind11::detail::cloudViewer_optional_caster< T > Struct Template Reference

#include <cloudViewer_pybind.h>

Inheritance diagram for pybind11::detail::cloudViewer_optional_caster< T >:

Public Types

using value_conv = make_caster< typename T::value_type >
 

Public Member Functions

bool load (handle src, bool convert)
 
 PYBIND11_TYPE_CASTER (T, _("Optional[")+value_conv::name+_("]"))
 

Static Public Member Functions

template<typename T_ >
static handle cast (T_ &&src, return_value_policy policy, handle parent)
 

Detailed Description

template<typename T>
struct pybind11::detail::cloudViewer_optional_caster< T >

Custom pybind11 type caster for cloudViewer::utility::optional, which backports C++17's std::optional. We need compiler supporting C++14 or newer. Typically, this can be used to handle "None" parameters from Python.

Example python function:

def add(a, b=None):
# Assuming a, b are int.
if b is None:
return a
else:
return a + b

Here's the equivalent C++ implementation:

m.def("add",
if (!b.has_value()) {
return a;
} else {
return a + b.value();
}
},
py::arg("a"), py::arg("b") = py::none()
);
constexpr bool has_value() const noexcept
Definition: Optional.h:440

Then this function can be called with:

add(1)
add(1, 2)
add(1, b=2)
add(1, b=None)

Definition at line 149 of file cloudViewer_pybind.h.

Member Typedef Documentation

◆ value_conv

template<typename T >
using pybind11::detail::cloudViewer_optional_caster< T >::value_conv = make_caster<typename T::value_type>

Definition at line 150 of file cloudViewer_pybind.h.

Member Function Documentation

◆ cast()

template<typename T >
template<typename T_ >
static handle pybind11::detail::cloudViewer_optional_caster< T >::cast ( T_ &&  src,
return_value_policy  policy,
handle  parent 
)
inlinestatic

Definition at line 153 of file cloudViewer_pybind.h.

◆ load()

template<typename T >
bool pybind11::detail::cloudViewer_optional_caster< T >::load ( handle  src,
bool  convert 
)
inline

Definition at line 161 of file cloudViewer_pybind.h.

References convert().

◆ PYBIND11_TYPE_CASTER()

template<typename T >
pybind11::detail::cloudViewer_optional_caster< T >::PYBIND11_TYPE_CASTER ( ,
_("Optional[")+value_conv::name+_("]")   
)

The documentation for this struct was generated from the following file: