MCPcopy Create free account
hub / github.com/pybind/pybind11 / unchecked_mutable_reference

Class unchecked_mutable_reference

include/pybind11/numpy.h:733–766  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

731
732template <typename T, ssize_t Dims>
733class unchecked_mutable_reference : public unchecked_reference<T, Dims> {
734 friend class pybind11::array;
735 using ConstBase = unchecked_reference<T, Dims>;
736 using ConstBase::ConstBase;
737 using ConstBase::Dynamic;
738
739public:
740 // Bring in const-qualified versions from base class
741 using ConstBase::operator();
742 using ConstBase::operator[];
743
744 /// Mutable, unchecked access to data at the given indices.
745 template <typename... Ix>
746 T &operator()(Ix... index) {
747 static_assert(ssize_t{sizeof...(Ix)} == Dims || Dynamic,
748 "Invalid number of indices for unchecked array reference");
749 return const_cast<T &>(ConstBase::operator()(index...));
750 }
751 /**
752 * Mutable, unchecked access data at the given index; this operator only participates if the
753 * reference is to a 1-dimensional array (or has runtime dimensions). When present, this is
754 * exactly equivalent to `obj(index)`.
755 */
756 template <ssize_t D = Dims, typename = enable_if_t<D == 1 || Dynamic>>
757 T &operator[](ssize_t index) {
758 return operator()(index);
759 }
760
761 /// Mutable pointer access to the data at the given indices.
762 template <typename... Ix>
763 T *mutable_data(Ix... ix) {
764 return &operator()(ssize_t(ix)...);
765 }
766};
767
768template <typename T, ssize_t Dim>
769struct type_caster<unchecked_reference<T, Dim>> {

Callers

nothing calls this directly

Calls 1

operator()Function · 0.70

Tested by

no test coverage detected