2013-08-27 19:17:17 +02:00
|
|
|
.. highlight:: c
|
|
|
|
|
|
|
|
.. _arr_view_assign:
|
|
|
|
|
|
|
|
Assignment to views
|
|
|
|
=========================
|
|
|
|
|
2014-10-17 18:15:19 +02:00
|
|
|
**Synopsis**:
|
2013-08-27 19:17:17 +02:00
|
|
|
|
2013-09-18 15:13:23 +02:00
|
|
|
template<typename RHS> array_view & operator=(RHS const & X);
|
|
|
|
|
|
|
|
*NB: The assignment operator is deleted for const_views.*
|
2013-08-27 19:17:17 +02:00
|
|
|
|
|
|
|
The `view classes` have a quite general assignment operator.
|
|
|
|
We will illustrate it on the `array_view` class, it is the same for `matrix` and `vector`.
|
|
|
|
|
|
|
|
|
2014-10-17 18:15:19 +02:00
|
|
|
* **RHS** can be:
|
2013-08-27 19:17:17 +02:00
|
|
|
|
|
|
|
* Anything that models the :ref:`ImmutableCuboidArray` concept
|
|
|
|
|
2014-10-17 18:15:19 +02:00
|
|
|
e.g.: array, array_view, matrix, matrix_view,
|
2013-08-27 19:17:17 +02:00
|
|
|
but also formal expression (See , e.g. A+B), or any custom object of your choice.
|
|
|
|
|
2014-10-17 18:15:19 +02:00
|
|
|
*Effect*:
|
2013-09-18 15:13:23 +02:00
|
|
|
Every elements viewed by the view are replaced by the evaluation of RHS.
|
2013-08-27 19:17:17 +02:00
|
|
|
|
2013-09-18 15:13:23 +02:00
|
|
|
*Precondition*
|
|
|
|
|
|
|
|
The shape of the view and of RHS must match exactly or behaviour is undefined.
|
2013-08-27 19:17:17 +02:00
|
|
|
|
2013-09-18 15:13:23 +02:00
|
|
|
If the debug macro, :ref:`TRIQS_ARRAYS_ENFORCE_BOUNDCHECK<arr_debug_macro>` is defined,
|
|
|
|
this condition is checked at runtime.
|
2013-08-27 19:17:17 +02:00
|
|
|
|
2014-10-17 18:15:19 +02:00
|
|
|
NB: We could lower this condition, since we don't need a domain here, just the evaluation on the indices...
|
2013-08-27 19:17:17 +02:00
|
|
|
|
|
|
|
* A scalar.
|
|
|
|
|
2014-10-17 18:15:19 +02:00
|
|
|
*Effect*:
|
2013-09-18 15:13:23 +02:00
|
|
|
Every elements viewed by the view are set to this scalar, except for the matrix_view,
|
|
|
|
where the matrix is set to the identity.
|
2013-08-27 19:17:17 +02:00
|
|
|
|
|
|
|
|
2014-10-17 18:15:19 +02:00
|
|
|
NB: no move assignment operator
|
2013-08-27 19:17:17 +02:00
|
|
|
---------------------------------------
|
|
|
|
|
2013-09-18 15:13:23 +02:00
|
|
|
Note that **there is no move assignment operators for views**.
|
|
|
|
If RHS is an rvalue reference, the regular operator= (view const &) is called, that
|
2013-08-27 19:17:17 +02:00
|
|
|
makes a copy of the data of RHS into the elements viewed by the view.
|
|
|
|
|
|
|
|
This behaviour is consistent with the fact that views are *not* regular types.
|
|
|
|
For example ::
|
|
|
|
|
|
|
|
array<double,2> A(3,3);
|
|
|
|
A(range(0,2), range(0,2)) = any_function_returning_a_new_2x2_array(....);
|
|
|
|
|
|
|
|
In this case, the expected behaviour is that the part of A views by view at l.h.s
|
2014-07-08 14:39:16 +02:00
|
|
|
is filled by the result of the function. There cannot be any move semantics here.
|
2013-08-27 19:17:17 +02:00
|
|
|
|
|
|
|
As a result, std::swap algorithm does not work properly for view, hence it has
|
|
|
|
been explicitely *deleted*. A swap function (found by ADL) is provided instead.
|