3
0
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:
Olivier Parcollet 2013-10-22 14:11:07 +02:00
parent dcb1386630
commit 1d929c1a91
4 changed files with 39 additions and 6 deletions

View File

@ -2,7 +2,7 @@
* *
* TRIQS: a Toolbox for Research in Interacting Quantum Systems * 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 * 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 * 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);} friend void swap( array_view & A, array_view & B) { A.swap_me(B);}
/// Rebind the view /// 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 /// 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; } template<typename RHS> array_view & operator=(RHS const & X) { triqs_arrays_assign_delegation(*this,X); return *this; }

View File

@ -33,10 +33,16 @@ namespace triqs { namespace arrays {
// puts the contents of RHS into LHS. LHS must be an indexmap_storage_pair // puts the contents of RHS into LHS. LHS must be an indexmap_storage_pair
// it is specialized in various cases for optimisation. // it is specialized in various cases for optimisation.
template<typename LHS, typename RHS> 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> 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)\ #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;}\ template<typename RHS> MYTYPE & operator +=(RHS const & rhs) { triqs_arrays_compound_assign_delegation (*this,rhs, mpl::char_<'A'>()); return *this;}\

View File

@ -80,7 +80,16 @@ namespace triqs { namespace arrays {
friend void swap( matrix_view & A, matrix_view & B) { A.swap_me(B);} friend void swap( matrix_view & A, matrix_view & B) { A.swap_me(B);}
/// Rebind the view /// 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. */ /** 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; } template<typename RHS> matrix_view & operator=(const RHS & X) {triqs_arrays_assign_delegation(*this,X); return *this; }

View File

@ -72,7 +72,16 @@ namespace triqs { namespace arrays {
friend void swap( vector_view & A, vector_view & B) { A.swap_me(B);} friend void swap( vector_view & A, vector_view & B) { A.swap_me(B);}
/// Rebind the view /// 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. */ /** 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; } template<typename RHS> vector_view & operator=(const RHS & X) { triqs_arrays_assign_delegation(*this,X); return *this; }