Skip to content

Commit

Permalink
minor code style updates
Browse files Browse the repository at this point in the history
  • Loading branch information
wjakob committed Sep 12, 2024
1 parent 30e96b7 commit 87a418a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions include/nanobind/nb_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,21 @@ template <typename Caster>
constexpr bool is_class_caster_v = detail::detector<void, is_class_caster_test, Caster>::value;

// Primary template
template<typename T, typename SFINAE = void>
template<typename T, typename = int>
struct is_complex : std::false_type {};

// Specialization if `T` is complex, i.e., `T` has a member type `value_type`,
// member functions `real()` and `imag()` that return such, and the size of
// `T` is twice that of `value_type`.
template<typename T>
struct is_complex<T, std::enable_if_t<std::is_same_v<
decltype(std::declval<T>().real()),
typename T::value_type>
&& std::is_same_v<
decltype(std::declval<T>().imag()),
typename T::value_type>
&& (sizeof(T) ==
2 * sizeof(typename T::value_type))>>
struct is_complex<T, enable_if_t<std::is_same_v<
decltype(std::declval<T>().real()),
typename T::value_type>
&& std::is_same_v<
decltype(std::declval<T>().imag()),
typename T::value_type>
&& (sizeof(T) ==
2 * sizeof(typename T::value_type))>>
: std::true_type {};

/// True if the type `T` is a complete type representing a complex number.
Expand Down
8 changes: 4 additions & 4 deletions src/nb_enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,21 @@ bool enum_from_python(const std::type_info *tp, PyObject *o, int64_t *out, uint8
return false;

if ((t->flags & (uint32_t) enum_flags::is_flag) != 0 && Py_TYPE(o) == t->type_py) {
PyObject *pValue = PyObject_GetAttrString(o, "value");
if (pValue == nullptr) {
PyObject *value_o = PyObject_GetAttrString(o, "value");
if (value_o == nullptr) {
PyErr_Clear();
return false;
}
if ((t->flags & (uint32_t) enum_flags::is_signed)) {
long long value = PyLong_AsLongLong(pValue);
long long value = PyLong_AsLongLong(value_o);
if (value == -1 && PyErr_Occurred()) {
PyErr_Clear();
return false;
}
*out = (int64_t) value;
return true;
} else {
unsigned long long value = PyLong_AsUnsignedLongLong(pValue);
unsigned long long value = PyLong_AsUnsignedLongLong(value_o);
if (value == (unsigned long long) -1 && PyErr_Occurred()) {
PyErr_Clear();
return false;
Expand Down

0 comments on commit 87a418a

Please sign in to comment.