3#ifndef TETL_LINALG_PROXY_REFERENCE_HPP
4#define TETL_LINALG_PROXY_REFERENCE_HPP
9namespace etl::linalg::detail {
11struct proxy_reference_base { };
13template <
typename Reference,
typename Value,
typename Derived>
14struct proxy_reference : proxy_reference_base {
15 using reference_type = Reference;
16 using value_type = Value;
17 using derived_type = Derived;
19 constexpr explicit proxy_reference(Reference reference)
20 : _reference(reference)
24 constexpr operator value_type() const
26 return static_cast<value_type
>(
static_cast<Derived const&
>(*this).to_value(_reference));
29 constexpr friend auto operator-(derived_type
const& cs) {
return -value_type(cs); }
31 template <
typename Rhs>
33 constexpr friend auto operator+(derived_type lhs, Rhs rhs)
35 using rhs_value_type =
typename Rhs::value_type;
36 return value_type(lhs) + rhs_value_type(rhs);
39 template <
typename Rhs>
41 constexpr friend auto operator+(derived_type lhs, Rhs rhs)
43 return value_type(lhs) + rhs;
46 template <
typename Lhs>
48 constexpr friend auto operator+(Lhs lhs, derived_type rhs)
50 return lhs + value_type(rhs);
53 template <
typename Rhs>
55 constexpr friend auto operator-(derived_type lhs, Rhs rhs)
57 using rhs_value_type =
typename Rhs::value_type;
58 return value_type(lhs) - rhs_value_type(rhs);
61 template <
typename Rhs>
63 constexpr friend auto operator-(derived_type lhs, Rhs rhs)
65 return value_type(lhs) - rhs;
68 template <
typename Lhs>
70 constexpr friend auto operator-(Lhs lhs, derived_type rhs)
72 return lhs - value_type(rhs);
75 template <
typename Rhs>
77 constexpr friend auto operator*(derived_type lhs, Rhs rhs)
79 using rhs_value_type =
typename Rhs::value_type;
80 return value_type(lhs) * rhs_value_type(rhs);
83 template <
typename Rhs>
85 constexpr friend auto operator*(derived_type lhs, Rhs rhs)
87 return value_type(lhs) * rhs;
90 template <
typename Lhs>
92 constexpr friend auto operator*(Lhs lhs, derived_type rhs)
94 return lhs * value_type(rhs);
97 template <
typename Rhs>
99 constexpr friend auto operator/(derived_type lhs, Rhs rhs)
101 using rhs_value_type =
typename Rhs::value_type;
102 return value_type(lhs) / rhs_value_type(rhs);
105 template <
typename Rhs>
107 constexpr friend auto operator/(derived_type lhs, Rhs rhs)
109 return value_type(lhs) / rhs;
112 template <
typename Lhs>
114 constexpr friend auto operator/(Lhs lhs, derived_type rhs)
116 return lhs / value_type(rhs);
119 constexpr friend auto abs(derived_type
const& x)
121 return abs_if_needed(value_type(
static_cast<this_type const&
>(x)));
124 constexpr friend auto real(derived_type
const& x)
126 return real_if_needed(value_type(
static_cast<this_type const&
>(x)));
129 constexpr friend auto imag(derived_type
const& x)
131 return imag_if_needed(value_type(
static_cast<this_type const&
>(x)));
134 constexpr friend auto conj(derived_type
const& x)
136 return conj_if_needed(value_type(
static_cast<this_type const&
>(x)));
140 using this_type = proxy_reference<Reference, Value, Derived>;
141 Reference _reference;
constexpr bool is_base_of_v
Definition is_base_of.hpp:39