proxsuite 0.6.7
The Advanced Proximal Optimization Toolbox
Loading...
Searching...
No Matches
ref.hpp
Go to the documentation of this file.
1#ifndef VEG_REF_HPP_VQCOSD7RS
2#define VEG_REF_HPP_VQCOSD7RS
3
8
9namespace proxsuite {
10namespace linalg {
11namespace veg {
12namespace cmp {
13namespace ref {
14struct RefBase
15{};
16} // namespace ref
17namespace mut {
19{};
20} // namespace mut
21} // namespace cmp
22
23namespace nb {
24struct ref;
25struct mut;
26} // namespace nb
27
28template<typename T>
30{
31private:
32 T const* ptr{};
33 VEG_INLINE constexpr Ref() = default;
34 VEG_INLINE constexpr Ref(T const* p) noexcept
35 : ptr{ p }
36 {
37 }
38 friend struct nb::ref;
39
40public:
42 {
43 return *ptr;
44 }
46 {
47 return *ptr;
48 }
50 -> T const*
51 {
52 return ptr;
53 }
54};
55namespace nb {
56struct ref
57{
58 template<typename T>
59 constexpr auto operator()(T const& r) const noexcept -> Ref<T>
60 {
61 return mem::addressof(r);
62 }
63};
64} // namespace nb
65
66template<typename T>
68{
69private:
70 T* ptr;
71 VEG_INLINE constexpr RefMut() = default;
72 VEG_INLINE constexpr RefMut(T* p) noexcept
73 : ptr{ p }
74 {
75 }
76
77 friend struct nb::mut;
78
79public:
80 VEG_INLINE constexpr auto as_const() const noexcept -> Ref<T>
81 {
82 return nb::ref{}(*ptr);
83 }
84 VEG_NODISCARD VEG_INLINE constexpr auto get() const noexcept -> T&
85 {
86 return *ptr;
87 }
89 {
90 return *ptr;
91 }
93 {
94 return ptr;
95 }
96};
97
98namespace nb {
99struct deref
100{
101 template<typename T>
102 constexpr auto operator()(Ref<T> r) const noexcept -> T const&
103 {
104 return r.get();
105 }
106};
108{
109 template<typename T>
110 constexpr auto operator()(RefMut<T> r) const noexcept -> T&
111 {
112 return r.get();
113 }
114};
115
116struct mut
117{
118 VEG_TEMPLATE(typename T,
120 constexpr auto
121 operator(),
122 (r, T&&))
123 const noexcept -> RefMut<meta::uncvref_t<T>> { return mem::addressof(r); }
124};
125struct clone
126{
127 VEG_TEMPLATE(typename T,
128 requires(VEG_CONCEPT(copyable<T>)),
129 VEG_INLINE constexpr auto
130 operator(),
131 (arg, Ref<T>))
133 {
134 return T(arg.get());
135 }
136};
137} // namespace nb
140VEG_NIEBLOID(deref_mut);
143} // namespace veg
144} // namespace linalg
145} // namespace proxsuite
146
148#endif /* end of include guard VEG_REF_HPP_VQCOSD7RS */
#define VEG_CONCEPT(...)
Definition macros.hpp:1243
#define VEG_NIEBLOID(Name)
Definition macros.hpp:545
#define VEG_INLINE
Definition macros.hpp:118
typename _detail::_meta::unref< T & >::type unref_t
Definition core.hpp:268
#define VEG_NODISCARD
Definition prologue.hpp:97
#define VEG_NOEXCEPT_IF(...)
Definition prologue.hpp:31
VEG_NODISCARD VEG_INLINE constexpr auto operator*() const noexcept -> T &
Definition ref.hpp:88
VEG_NODISCARD VEG_INLINE constexpr auto get() const noexcept -> T &
Definition ref.hpp:84
VEG_INLINE constexpr auto as_const() const noexcept -> Ref< T >
Definition ref.hpp:80
VEG_NODISCARD VEG_INLINE constexpr auto operator->() const noexcept -> T *
Definition ref.hpp:92
VEG_NODISCARD VEG_INLINE constexpr auto operator*() const noexcept -> T const &
Definition ref.hpp:45
VEG_NODISCARD VEG_INLINE constexpr auto operator->() const noexcept -> T const *
Definition ref.hpp:49
VEG_NODISCARD VEG_INLINE constexpr auto get() const noexcept -> T const &
Definition ref.hpp:41
VEG_TEMPLATE(typename T, requires(VEG_CONCEPT(copyable< T >)), VEG_INLINE constexpr auto operator(),(arg, Ref< T >)) const VEG_NOEXCEPT_IF(VEG_CONCEPT(nothrow_copyable< T >)) -> T
Definition ref.hpp:127
constexpr auto operator()(RefMut< T > r) const noexcept -> T &
Definition ref.hpp:110
constexpr auto operator()(Ref< T > r) const noexcept -> T const &
Definition ref.hpp:102
VEG_TEMPLATE(typename T, requires(!VEG_CONCEPT(const_type< meta::unref_t< T > >)), constexpr auto operator(),(r, T &&)) const noexcept -> RefMut< meta::uncvref_t< T > >
Definition ref.hpp:118
constexpr auto operator()(T const &r) const noexcept -> Ref< T >
Definition ref.hpp:59