.. _program_listing_file__tmp_ws_src_proxsuite_include_proxsuite_linalg_veg_ref.hpp: Program Listing for File ref.hpp ================================ |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/proxsuite/include/proxsuite/linalg/veg/ref.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #ifndef VEG_REF_HPP_VQCOSD7RS #define VEG_REF_HPP_VQCOSD7RS #include "proxsuite/linalg/veg/type_traits/tags.hpp" #include "proxsuite/linalg/veg/type_traits/constructible.hpp" #include "proxsuite/linalg/veg/memory/address.hpp" #include "proxsuite/linalg/veg/internal/prologue.hpp" namespace proxsuite { namespace linalg { namespace veg { namespace cmp { namespace ref { struct RefBase {}; } // namespace ref namespace mut { struct RefMutBase {}; } // namespace mut } // namespace cmp namespace nb { struct ref; struct mut; } // namespace nb template struct Ref : cmp::ref::RefBase { private: T const* ptr{}; VEG_INLINE constexpr Ref() = default; VEG_INLINE constexpr Ref(T const* p) noexcept : ptr{ p } { } friend struct nb::ref; public: VEG_NODISCARD VEG_INLINE constexpr auto get() const noexcept -> T const& { return *ptr; } VEG_NODISCARD VEG_INLINE constexpr auto operator*() const noexcept -> T const& { return *ptr; } VEG_NODISCARD VEG_INLINE constexpr auto operator->() const noexcept -> T const* { return ptr; } }; namespace nb { struct ref { template constexpr auto operator()(T const& r) const noexcept -> Ref { return mem::addressof(r); } }; } // namespace nb template struct RefMut : cmp::mut::RefMutBase { private: T* ptr; VEG_INLINE constexpr RefMut() = default; VEG_INLINE constexpr RefMut(T* p) noexcept : ptr{ p } { } friend struct nb::mut; public: VEG_INLINE constexpr auto as_const() const noexcept -> Ref { return nb::ref{}(*ptr); } VEG_NODISCARD VEG_INLINE constexpr auto get() const noexcept -> T& { return *ptr; } VEG_NODISCARD VEG_INLINE constexpr auto operator*() const noexcept -> T& { return *ptr; } VEG_NODISCARD VEG_INLINE constexpr auto operator->() const noexcept -> T* { return ptr; } }; namespace nb { struct deref { template constexpr auto operator()(Ref r) const noexcept -> T const& { return r.get(); } }; struct deref_mut { template constexpr auto operator()(RefMut r) const noexcept -> T& { return r.get(); } }; struct mut { VEG_TEMPLATE(typename T, requires(!VEG_CONCEPT(const_type>)), constexpr auto operator(), (r, T&&)) const noexcept -> RefMut> { return mem::addressof(r); } }; struct clone { VEG_TEMPLATE(typename T, requires(VEG_CONCEPT(copyable)), VEG_INLINE constexpr auto operator(), (arg, Ref)) const VEG_NOEXCEPT_IF(VEG_CONCEPT(nothrow_copyable))->T { return T(arg.get()); } }; } // namespace nb VEG_NIEBLOID(clone); VEG_NIEBLOID(deref); VEG_NIEBLOID(deref_mut); VEG_NIEBLOID(ref); VEG_NIEBLOID(mut); } // namespace veg } // namespace linalg } // namespace proxsuite #include "proxsuite/linalg/veg/internal/epilogue.hpp" #endif /* end of include guard VEG_REF_HPP_VQCOSD7RS */