operators: Explicitly expose py::hash(py::self)

Add warnings about extending STL
This commit is contained in:
Eric Cousineau
2020-05-22 00:43:01 -04:00
committed by Wenzel Jakob
parent 5309573005
commit 4e3d9fea74
3 changed files with 41 additions and 3 deletions

View File

@@ -147,6 +147,9 @@ PYBIND11_INPLACE_OPERATOR(ixor, operator^=, l ^= r)
PYBIND11_INPLACE_OPERATOR(ior, operator|=, l |= r)
PYBIND11_UNARY_OPERATOR(neg, operator-, -l)
PYBIND11_UNARY_OPERATOR(pos, operator+, +l)
// WARNING: This usage of `abs` should only be done for existing STL overloads.
// Adding overloads directly in to the `std::` namespace is advised against:
// https://en.cppreference.com/w/cpp/language/extending_std
PYBIND11_UNARY_OPERATOR(abs, abs, std::abs(l))
PYBIND11_UNARY_OPERATOR(hash, hash, std::hash<L>()(l))
PYBIND11_UNARY_OPERATOR(invert, operator~, (~l))
@@ -160,6 +163,8 @@ PYBIND11_UNARY_OPERATOR(float, float_, (double) l)
NAMESPACE_END(detail)
using detail::self;
// Add named operators so that they are accessible via `py::`.
using detail::hash;
NAMESPACE_END(PYBIND11_NAMESPACE)