mirror of
https://github.com/pybind/pybind11.git
synced 2025-02-19 23:20:43 +00:00
Add detail::is_pod_struct<T> helper
This commit is contained in:
parent
d0bafd90e0
commit
73f56830f8
@ -23,7 +23,19 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
NAMESPACE_BEGIN(pybind11)
|
NAMESPACE_BEGIN(pybind11)
|
||||||
namespace detail { template <typename type, typename SFINAE = void> struct npy_format_descriptor { }; }
|
namespace detail {
|
||||||
|
template <typename type, typename SFINAE = void> struct npy_format_descriptor { };
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct is_pod_struct {
|
||||||
|
enum { value = std::is_pod<T>::value && // offsetof only works correctly for POD types
|
||||||
|
!std::is_integral<T>::value &&
|
||||||
|
!std::is_same<T, float>::value &&
|
||||||
|
!std::is_same<T, bool>::value &&
|
||||||
|
!std::is_same<T, std::complex<float>>::value &&
|
||||||
|
!std::is_same<T, std::complex<double>>::value };
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
class array : public buffer {
|
class array : public buffer {
|
||||||
public:
|
public:
|
||||||
@ -156,14 +168,8 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> struct format_descriptor
|
template <typename T>
|
||||||
<T, typename std::enable_if<std::is_pod<T>::value &&
|
struct format_descriptor<T, typename std::enable_if<detail::is_pod_struct<T>::value>::type> {
|
||||||
!std::is_integral<T>::value &&
|
|
||||||
!std::is_same<T, float>::value &&
|
|
||||||
!std::is_same<T, bool>::value &&
|
|
||||||
!std::is_same<T, std::complex<float>>::value &&
|
|
||||||
!std::is_same<T, std::complex<double>>::value>::type>
|
|
||||||
{
|
|
||||||
static const char *format() {
|
static const char *format() {
|
||||||
return detail::npy_format_descriptor<T>::format();
|
return detail::npy_format_descriptor<T>::format();
|
||||||
}
|
}
|
||||||
@ -217,13 +223,8 @@ struct field_descriptor {
|
|||||||
object descr;
|
object descr;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> struct npy_format_descriptor
|
template <typename T>
|
||||||
<T, typename std::enable_if<std::is_pod<T>::value && // offsetof only works correctly for POD types
|
struct npy_format_descriptor<T, typename std::enable_if<is_pod_struct<T>::value>::type>
|
||||||
!std::is_integral<T>::value &&
|
|
||||||
!std::is_same<T, float>::value &&
|
|
||||||
!std::is_same<T, bool>::value &&
|
|
||||||
!std::is_same<T, std::complex<float>>::value &&
|
|
||||||
!std::is_same<T, std::complex<double>>::value>::type>
|
|
||||||
{
|
{
|
||||||
static PYBIND11_DESCR name() { return _("user-defined"); }
|
static PYBIND11_DESCR name() { return _("user-defined"); }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user