3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-27 23:03:51 +01:00
dft_tools/doc/reference/arrays/containers/view_assign.rst

62 lines
2.0 KiB
ReStructuredText
Raw Normal View History

2013-08-27 19:17:17 +02:00
.. highlight:: c
.. _arr_view_assign:
Assignment to views
=========================
**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`.
* **RHS** can be:
2013-08-27 19:17:17 +02:00
* Anything that models the :ref:`ImmutableCuboidArray` concept
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.
*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
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.
*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
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
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.