Expression Templates Library (ETL)
assignable.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2014-2023 Baptiste Wicht
3 // Distributed under the terms of the MIT License.
4 // (See accompanying file LICENSE or copy at
5 // http://opensource.org/licenses/MIT)
6 //=======================================================================
7 
8 #pragma once
9 
10 #include <concepts>
11 #include "etl/impl/transpose.hpp"
12 #include "etl/impl/fft.hpp"
13 
19 namespace etl {
20 
24 template <typename D, typename V>
25 struct assignable {
26  using derived_t = D;
27  using value_type = V;
28 
34  template <etl_expr E>
35  derived_t& operator=(E&& e) {
36  validate_assign(as_derived(), e);
37 
38  if constexpr (!decay_traits<E>::is_linear) {
39  if (e.alias(as_derived())) {
40  auto tmp = etl::force_temporary_dim_only(as_derived());
41 
42  e.assign_to(tmp);
43 
44  as_derived() = tmp;
45  } else {
46  e.assign_to(as_derived());
47  }
48  } else {
49  e.assign_to(as_derived());
50  }
51 
52  return as_derived();
53  }
54 
61  if constexpr (decay_traits<derived_t>::is_direct) {
62  direct_fill(as_derived(), v);
63  } else {
64  std::fill(as_derived().begin(), as_derived().end(), v);
65  }
66 
67  return as_derived();
68  }
69 
75  template <std_container Container>
76  derived_t& operator=(const Container& vec) requires(std::convertible_to<typename Container::value_type, value_type>) {
77  validate_assign(as_derived(), vec);
78 
79  std::copy(vec.begin(), vec.end(), as_derived().begin());
80 
81  return as_derived();
82  }
83 
84 private:
89  derived_t& as_derived() noexcept {
90  return *static_cast<derived_t*>(this);
91  }
92 };
93 
94 } //end of namespace etl
value_t< T > value_type
The value type.
Definition: assignable.hpp:27
D D
The number of dimensions.
Definition: dyn_matrix_view.hpp:24
derived_t & operator=(const value_type &v)
Assign the given expression to the unary expression.
Definition: assignable.hpp:60
Implementations of inplace matrix transposition.
Traits to get information about ETL types.
Definition: tmp.hpp:68
Root namespace for the ETL library.
Definition: adapter.hpp:15
void direct_fill(E &&mat, V value)
Fill the given ETL value class with the given value.
Definition: direct_fill.hpp:25
derived_t & operator=(E &&e)
Assign the given expression to the unary expression.
Definition: assignable.hpp:35
View that shows a 2D sub matrix of an expression.
Definition: expr_fwd.hpp:62
derived_t & operator=(const Container &vec) requires(std
Assign the given container to the unary expression.
Definition: assignable.hpp:76
requires(D > 0) struct dyn_base
Matrix with run-time fixed dimensions.
Definition: dyn_base.hpp:113
CRTP class to inject assign operations to matrix and vector structures.
Definition: assignable.hpp:25
decltype(auto) force_temporary_dim_only(E &&expr)
Force a temporary out of the expression with the same dimensions, but the content is not defined...
Definition: temporary.hpp:156