mirror of
https://github.com/triqs/dft_tools
synced 2024-12-25 05:43:40 +01:00
arrays: add rebind const_view from view
- also add some static assert to forbid += and co on const_view
This commit is contained in:
parent
dcb1386630
commit
1d929c1a91
@ -2,7 +2,7 @@
|
||||
*
|
||||
* TRIQS: a Toolbox for Research in Interacting Quantum Systems
|
||||
*
|
||||
* Copyright (C) 2011 by O. Parcollet
|
||||
* Copyright (C) 2011-2013 by O. Parcollet
|
||||
*
|
||||
* TRIQS is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
@ -73,7 +73,16 @@ namespace triqs { namespace arrays {
|
||||
friend void swap( array_view & A, array_view & B) { A.swap_me(B);}
|
||||
|
||||
/// Rebind the view
|
||||
void rebind (array_view const & X) { this->indexmap_ = X.indexmap_; this->storage_ = X.storage_;}
|
||||
void rebind(array_view const& X) {
|
||||
this->indexmap_ = X.indexmap_;
|
||||
this->storage_ = X.storage_;
|
||||
}
|
||||
|
||||
// rebind the other view, iif this is const, and the other is not.
|
||||
template <bool C = IsConst> ENABLE_IFC(C) rebind(array_view<ValueType, Rank, Opt, TraversalOrder, Borrowed, !IsConst> const& X) {
|
||||
this->indexmap_ = X.indexmap_;
|
||||
this->storage_ = X.storage_;
|
||||
}
|
||||
|
||||
/// Assignment. The size of the array MUST match exactly, except in the empty case
|
||||
template<typename RHS> array_view & operator=(RHS const & X) { triqs_arrays_assign_delegation(*this,X); return *this; }
|
||||
|
@ -33,10 +33,16 @@ namespace triqs { namespace arrays {
|
||||
// puts the contents of RHS into LHS. LHS must be an indexmap_storage_pair
|
||||
// it is specialized in various cases for optimisation.
|
||||
template<typename LHS, typename RHS>
|
||||
void triqs_arrays_assign_delegation (LHS & lhs, const RHS & rhs ) { assignment::impl<LHS,RHS,'E'>(lhs,rhs).invoke();}
|
||||
void triqs_arrays_assign_delegation (LHS & lhs, const RHS & rhs ) {
|
||||
static_assert( !LHS::is_const, "Can not assign to a const view !");
|
||||
assignment::impl<LHS, RHS, 'E'>(lhs, rhs).invoke();
|
||||
}
|
||||
|
||||
template<typename LHS, typename RHS, char OP>
|
||||
void triqs_arrays_compound_assign_delegation (LHS & lhs, const RHS & rhs, mpl::char_<OP> ) { assignment::impl<LHS,RHS,OP>(lhs,rhs).invoke();}
|
||||
void triqs_arrays_compound_assign_delegation (LHS & lhs, const RHS & rhs, mpl::char_<OP> ) {
|
||||
static_assert( !LHS::is_const, "Can not apply a compound operator to a const view !");
|
||||
assignment::impl<LHS, RHS, OP>(lhs, rhs).invoke();
|
||||
}
|
||||
|
||||
#define TRIQS_DEFINE_COMPOUND_OPERATORS(MYTYPE)\
|
||||
template<typename RHS> MYTYPE & operator +=(RHS const & rhs) { triqs_arrays_compound_assign_delegation (*this,rhs, mpl::char_<'A'>()); return *this;}\
|
||||
|
@ -80,7 +80,16 @@ namespace triqs { namespace arrays {
|
||||
friend void swap( matrix_view & A, matrix_view & B) { A.swap_me(B);}
|
||||
|
||||
/// Rebind the view
|
||||
void rebind (matrix_view const & X) { this->indexmap_ = X.indexmap_; this->storage_ = X.storage_;}
|
||||
void rebind(matrix_view const& X) {
|
||||
this->indexmap_ = X.indexmap_;
|
||||
this->storage_ = X.storage_;
|
||||
}
|
||||
|
||||
// rebind the other view, iif this is const, and the other is not.
|
||||
template <bool C = IsConst> ENABLE_IFC(C) rebind(matrix_view<ValueType, Opt, TraversalOrder, Borrowed, !IsConst> const& X) {
|
||||
this->indexmap_ = X.indexmap_;
|
||||
this->storage_ = X.storage_;
|
||||
}
|
||||
|
||||
/** Assignement. The size of the array MUST match exactly. */
|
||||
template<typename RHS> matrix_view & operator=(const RHS & X) {triqs_arrays_assign_delegation(*this,X); return *this; }
|
||||
|
@ -72,7 +72,16 @@ namespace triqs { namespace arrays {
|
||||
friend void swap( vector_view & A, vector_view & B) { A.swap_me(B);}
|
||||
|
||||
/// Rebind the view
|
||||
void rebind (vector_view const & X) { this->indexmap_ = X.indexmap_; this->storage_ = X.storage_;}
|
||||
void rebind(vector_view const& X) {
|
||||
this->indexmap_ = X.indexmap_;
|
||||
this->storage_ = X.storage_;
|
||||
}
|
||||
|
||||
// rebind the other view, iif this is const, and the other is not.
|
||||
template <bool C = IsConst> ENABLE_IFC(C) rebind(vector_view<ValueType, Opt, Borrowed, !IsConst> const& X) {
|
||||
this->indexmap_ = X.indexmap_;
|
||||
this->storage_ = X.storage_;
|
||||
}
|
||||
|
||||
/** Assignment. The size of the array MUST match exactly. */
|
||||
template<typename RHS> vector_view & operator=(const RHS & X) { triqs_arrays_assign_delegation(*this,X); return *this; }
|
||||
|
Loading…
Reference in New Issue
Block a user