diff --git a/triqs/arrays/array.hpp b/triqs/arrays/array.hpp index 480b35b3..f64dc29e 100644 --- a/triqs/arrays/array.hpp +++ b/triqs/arrays/array.hpp @@ -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 ENABLE_IFC(C) rebind(array_view 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 array_view & operator=(RHS const & X) { triqs_arrays_assign_delegation(*this,X); return *this; } diff --git a/triqs/arrays/impl/assignment.hpp b/triqs/arrays/impl/assignment.hpp index 4fbab864..3b2901dd 100644 --- a/triqs/arrays/impl/assignment.hpp +++ b/triqs/arrays/impl/assignment.hpp @@ -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 - void triqs_arrays_assign_delegation (LHS & lhs, const RHS & rhs ) { assignment::impl(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).invoke(); + } template - void triqs_arrays_compound_assign_delegation (LHS & lhs, const RHS & rhs, mpl::char_ ) { assignment::impl(lhs,rhs).invoke();} + void triqs_arrays_compound_assign_delegation (LHS & lhs, const RHS & rhs, mpl::char_ ) { + static_assert( !LHS::is_const, "Can not apply a compound operator to a const view !"); + assignment::impl(lhs, rhs).invoke(); + } #define TRIQS_DEFINE_COMPOUND_OPERATORS(MYTYPE)\ template MYTYPE & operator +=(RHS const & rhs) { triqs_arrays_compound_assign_delegation (*this,rhs, mpl::char_<'A'>()); return *this;}\ diff --git a/triqs/arrays/matrix.hpp b/triqs/arrays/matrix.hpp index 2c23ebaf..9d3ac940 100644 --- a/triqs/arrays/matrix.hpp +++ b/triqs/arrays/matrix.hpp @@ -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 ENABLE_IFC(C) rebind(matrix_view const& X) { + this->indexmap_ = X.indexmap_; + this->storage_ = X.storage_; + } /** Assignement. The size of the array MUST match exactly. */ template matrix_view & operator=(const RHS & X) {triqs_arrays_assign_delegation(*this,X); return *this; } diff --git a/triqs/arrays/vector.hpp b/triqs/arrays/vector.hpp index d37f8d82..e5009355 100644 --- a/triqs/arrays/vector.hpp +++ b/triqs/arrays/vector.hpp @@ -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 ENABLE_IFC(C) rebind(vector_view const& X) { + this->indexmap_ = X.indexmap_; + this->storage_ = X.storage_; + } /** Assignment. The size of the array MUST match exactly. */ template vector_view & operator=(const RHS & X) { triqs_arrays_assign_delegation(*this,X); return *this; }