diff --git a/test/triqs/arrays/alias_const_view.cpp b/test/triqs/arrays/alias_const_view.cpp
deleted file mode 100644
index 343e5303..00000000
--- a/test/triqs/arrays/alias_const_view.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
- *
- * TRIQS: a Toolbox for Research in Interacting Quantum Systems
- *
- * Copyright (C) 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
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * TRIQS. If not, see .
- *
- ******************************************************************************/
-
-#include "./common.hpp"
-#include "./src/array.hpp"
-#include
-
-//using std::cout; using std::endl;
-using namespace triqs::arrays;
-#include
-
-
-template
-void f (array_const_view const & a) {
- std::cout << a << std::endl ;
-}
-
-int main(int argc, char **argv) {
-
- array A (2,3);
- A() =3;
-
- f(A());
-
-}
-
-
-
-
diff --git a/test/triqs/arrays/array_cache2.cpp b/test/triqs/arrays/array_cache2.cpp
index 3aa8b815..81b3ed17 100644
--- a/test/triqs/arrays/array_cache2.cpp
+++ b/test/triqs/arrays/array_cache2.cpp
@@ -28,7 +28,7 @@
using namespace triqs::arrays;
-void f( array_view & A, long u) {
+void f( array_view A, long u) {
A(0,0) = u;
}
diff --git a/test/triqs/arrays/const_view.cpp b/test/triqs/arrays/const_view.cpp
index a4786e34..fcc715dd 100644
--- a/test/triqs/arrays/const_view.cpp
+++ b/test/triqs/arrays/const_view.cpp
@@ -24,18 +24,37 @@
using namespace triqs::arrays;
+
+template void f(array_view const &a) {
+ std::cout << a << std::endl;
+}
+
+void f2(array_const_view const &a) { std::cout << a << std::endl; }
+
int main(int argc, char **argv) {
- const array A = {1,2,3,4};
+ {
+ array A(2, 3);
+ A() = 3;
+ auto const &AA = A;
+ f2(A());
- std::cerr << A.opt_flags< Vc = A();
+ //array_view V = Vc;
+ }
+//#define SHOULD_NOT_COMPILE
+#ifdef SHOULD_NOT_COMPILE
+ {
+ const array A = {1, 2, 3, 4};
+
+ // None of this should compile
+ A(0) = 2;
+ A()(0) = 2;
+ A(range(0,2))(0) = 10;
+ }
+#endif
return 0;
}
diff --git a/test/triqs/arrays/temp_slice.cpp b/test/triqs/arrays/temp_slice.cpp
index 27ba486c..69722606 100644
--- a/test/triqs/arrays/temp_slice.cpp
+++ b/test/triqs/arrays/temp_slice.cpp
@@ -28,7 +28,7 @@ auto bad (array const & a) DECL_AND_RETURN (a(range(0,3)));
auto bad2 (array const & a) DECL_AND_RETURN (a(0));
-array_view good(array const & a) {return a(range(0,3));}
+array_const_view good(array const & a) {return a(range(0,3));}
int main(int argc, char **argv) {
diff --git a/test/triqs/gfs/gf_scalar.cpp b/test/triqs/gfs/gf_scalar.cpp
index bcc47dd7..25747eb1 100644
--- a/test/triqs/gfs/gf_scalar.cpp
+++ b/test/triqs/gfs/gf_scalar.cpp
@@ -15,7 +15,7 @@ int main() {
// test hdf5
H5::H5File file("gf_scalar.h5", H5F_ACC_TRUNC);
h5_write(file, "g", G);
- h5_write(file, "gm", reinterpret_scalar_valued_gf_as_matrix_valued(G));
+ h5_write(file, "gm", reinterpret_scalar_valued_gf_as_matrix_valued(G()));
}
TRIQS_CATCH_AND_ABORT;
diff --git a/test/triqs/gfs/gfv2.cpp b/test/triqs/gfs/gfv2.cpp
index 7d2d1d83..733d5eb8 100644
--- a/test/triqs/gfs/gfv2.cpp
+++ b/test/triqs/gfs/gfv2.cpp
@@ -29,7 +29,7 @@ int main() {
TEST( G( 0) ) ;
Gv.on_mesh(0) = 0;
- auto Gv2 = slice_target(G,range(0,1),range(0,1));
+ auto Gv2 = slice_target(G(),range(0,1),range(0,1));
TEST( Gv2( 0) ) ;
Gv2.on_mesh(0) = 10;
TEST( Gv2( 0) ) ;
diff --git a/triqs/arrays/array.hpp b/triqs/arrays/array.hpp
index 143f6a0f..480b35b3 100644
--- a/triqs/arrays/array.hpp
+++ b/triqs/arrays/array.hpp
@@ -28,32 +28,36 @@
#include "impl/flags.hpp"
namespace triqs { namespace arrays {
- template class array_view;
+ template class array_view;
template class array;
// ---------------------- array_view --------------------------------
#define IMPL_TYPE indexmap_storage_pair< indexmaps::cuboid::map, \
- storages::shared_block, Opt, TraversalOrder, Tag::array_view >
+ storages::shared_block, Opt, TraversalOrder, IsConst, Tag::array_view >
- template
- class array_view : Tag::array_view, TRIQS_CONCEPT_TAG_NAME(MutableArray), public IMPL_TYPE {
+ template
+ class array_view: Tag::array_view, TRIQS_CONCEPT_TAG_NAME(MutableArray), public IMPL_TYPE {
static_assert( Rank>0, " Rank must be >0");
public:
typedef typename IMPL_TYPE::indexmap_type indexmap_type;
typedef typename IMPL_TYPE::storage_type storage_type;
typedef array regular_type;
typedef array_view view_type;
+ typedef array_view const_view_type;
typedef array_view weak_view_type;
- /// Build from an IndexMap and a storage
- template array_view (indexmap_type const & Ind,S const & Mem): IMPL_TYPE(Ind, Mem) {}
+ /// Build from an IndexMap and a storage
+ template array_view(indexmap_type const& Ind, S const& Mem) : IMPL_TYPE(Ind, Mem) {}
/// Copy constructor
array_view(array_view const & X): IMPL_TYPE(X.indexmap(),X.storage()) {}
/// Build from anything that has an indexmap and a storage compatible with this class
- template array_view(const ISP & X): IMPL_TYPE(X.indexmap(),X.storage()) {}
+ template array_view(const ISP & X): IMPL_TYPE(X.indexmap(),X.storage()) {
+ // to be activated
+ static_assert(IsConst || (!ISP::is_const), "Can not construct a non const view from a const one !");
+ }
#ifdef TRIQS_WITH_PYTHON_SUPPORT
/// Build from a numpy.array (X is a borrowed reference) : throws if X is not a numpy.array
@@ -88,12 +92,12 @@ namespace triqs { namespace arrays {
#undef IMPL_TYPE
template
- using array_const_view = array_view;
+ using array_const_view = array_view;
//------------------------------- array ---------------------------------------------------
#define IMPL_TYPE indexmap_storage_pair< indexmaps::cuboid::map, \
- storages::shared_block, Opt, TraversalOrder, Tag::array_view >
+ storages::shared_block, Opt, TraversalOrder, false, Tag::array_view >
template
class array: Tag::array, TRIQS_CONCEPT_TAG_NAME(MutableArray), public IMPL_TYPE {
@@ -101,9 +105,10 @@ namespace triqs { namespace arrays {
typedef typename IMPL_TYPE::value_type value_type;
typedef typename IMPL_TYPE::storage_type storage_type;
typedef typename IMPL_TYPE::indexmap_type indexmap_type;
- typedef array regular_type;
- typedef array_view view_type;
- typedef array_view weak_view_type;
+ typedef array regular_type;
+ typedef array_view view_type;
+ typedef array_view const_view_type;
+ typedef array_view weak_view_type;
/// Empty array.
explicit array(memory_layout ml = memory_layout(IMPL_TYPE::indexmap_type::traversal_order)) :IMPL_TYPE(ml){}
@@ -206,16 +211,16 @@ namespace triqs { namespace arrays {
//----------------------------------------------------------------------------------
// how to build the view type ....
- template < class V, int R, ull_t Opt, ull_t TraversalOrder, bool Borrowed >
- struct ISPViewType< V, R, Opt, TraversalOrder,Tag::array_view, Borrowed> { typedef array_view type; };
+ template < class V, int R, ull_t Opt, ull_t TraversalOrder, bool Borrowed, bool IsConst >
+ struct ISPViewType< V, R, Opt, TraversalOrder,Tag::array_view, Borrowed,IsConst> { typedef array_view type; };
}}//namespace triqs::arrays
// The std::swap is WRONG for a view because of the copy/move semantics of view.
// Use swap instead (the correct one, found by ADL).
namespace std {
- template
- void swap( triqs::arrays::array_view & a , triqs::arrays::array_view & b)= delete;
+ template
+ void swap( triqs::arrays::array_view & a , triqs::arrays::array_view & b)= delete;
}
#include "./expression_template/array_algebra.hpp"
diff --git a/triqs/arrays/cache.hpp b/triqs/arrays/cache.hpp
index f276551b..9936f0bf 100644
--- a/triqs/arrays/cache.hpp
+++ b/triqs/arrays/cache.hpp
@@ -45,20 +45,19 @@ namespace triqs { namespace arrays {
template struct need_copy_ct : mpl::true_{};
template struct need_copy_ct)> :
mpl::not_ > {};
- //mpl::not_ >{};
- template class const_cache {
+ template class cache_impl {
protected:
typedef memory_layout< DataType::domain_type::rank> ml_t;
const ml_t ml;
- typename view_type_if_exists_else_type::type keeper;
+ typename std::conditional::type, typename view_type_if_exists_else_type::type>::type keeper;
static const bool CT_need_copy = need_copy_ct::value;
const bool need_copy;
- typedef typename CacheType::view_type exposed_view_type;
+ typedef typename std::conditional::type exposed_view_type;
struct internal_data {
CacheType copy;
exposed_view_type view;
- internal_data(const_cache const & P,ml_t ml) : copy(CacheType(P.keeper,ml)), view(copy) {
+ internal_data(cache_impl const & P,ml_t ml) : copy(CacheType(P.keeper,ml)), view(copy) {
#ifdef TRIQS_ARRAYS_CACHE_COPY_VERBOSE
std::cerr<< " Cache : copy made "<< std::endl<< " -- TRACE = --" << std::endl << triqs::utility::stack_trace() << std::endl;
#endif
@@ -68,18 +67,10 @@ namespace triqs { namespace arrays {
mutable std::shared_ptr _id;
internal_data & id() const { if (!_id) _id= std::make_shared(*this,ml); return *_id;}
- //exposed_view_type & view2 () { if (need_copy) return id().view; else return keeper;}
- //exposed_view_type const & view2 () const { if (need_copy) return id().view; else return keeper;}
-
// avoid compiling the transformation keeper-> exposed_view_type when it does not make sense
- exposed_view_type & view1 (mpl::false_) { if (need_copy) return id().view; else return keeper; }
- exposed_view_type const & view1 (mpl::false_) const { if (need_copy) return id().view; else return keeper;}
-
- exposed_view_type & view1 (mpl::true_) { return id().view; }
- exposed_view_type const & view1 (mpl::true_) const { return id().view; }
-
- exposed_view_type & view2 () { return view1(mpl::bool_());}
- exposed_view_type const & view2 () const { return view1(mpl::bool_());}
+ exposed_view_type view1 (mpl::false_) const { if (need_copy) return id().view; else return keeper;}
+ exposed_view_type view1 (mpl::true_) const { return id().view; }
+ exposed_view_type view2 () const { return view1(mpl::bool_());}
template
typename std::enable_if< ! is_amv_value_or_view_class::value, bool>::type
@@ -90,27 +81,31 @@ namespace triqs { namespace arrays {
need_copy_dynamic ( D const & x) const { return (x.indexmap().memory_indices_layout() != ml );}
public :
- const_cache (DataType const & x, ml_t ml_ = ml_t()):
+ cache_impl (DataType const & x, ml_t ml_ = ml_t()):
ml(ml_),keeper (x),
need_copy ( CT_need_copy || need_copy_dynamic(x) || (!has_contiguous_data(x)) ) {}
void update() { if (need_copy && _id) id().view = keeper;}
- exposed_view_type const & view () const { return view2();}
- operator exposed_view_type const & () const { return view2();}
+ exposed_view_type view () const { return view2();}
+ operator exposed_view_type () const { return view2();}
+ };
+
+ // Const case : just add the back copy in the destructor
+ template class const_cache : public cache_impl {
+ typedef cache_impl B;
+ typedef typename B::ml_t ml_t;
+ public :
+ const_cache (DataType const & x, ml_t ml = ml_t() ): B(x,ml) {}
};
// Non const case : just add the back copy in the destructor
- template class cache : const_cache {
+ template class cache : public cache_impl {
static_assert( is_amv_value_or_view_class::value, "non const cache only for regular classes and views, not expressions");
- typedef const_cache B;
+ typedef cache_impl B;
typedef typename B::ml_t ml_t;
public :
cache (DataType const & x, ml_t ml = ml_t() ): B(x,ml) {}
~cache() { back_update(); }
void back_update() { if (this->need_copy) this->keeper = this->id().view;}
- typename B::exposed_view_type & view () {return B::view2();}
- typename B::exposed_view_type const & view () const {return B::view2();}
- operator typename B::exposed_view_type & () {return B::view2();}
- operator typename B::exposed_view_type const & () const {return B::view2();}
};
}}//namespace triqs::arrays
#endif
diff --git a/triqs/arrays/h5/simple_read_write.hpp b/triqs/arrays/h5/simple_read_write.hpp
index 5d84e255..c544d855 100644
--- a/triqs/arrays/h5/simple_read_write.hpp
+++ b/triqs/arrays/h5/simple_read_write.hpp
@@ -28,6 +28,7 @@
namespace triqs { namespace arrays {
namespace h5_impl {
+ template const void * get_array_data_cptr ( array_const_view const & A) { return h5::get_data_ptr(&(A.storage()[0]));}
template const void * get_array_data_cptr ( array_view const & A) { return h5::get_data_ptr(&(A.storage()[0]));}
template const void * get_array_data_cptr ( array const & A) { return h5::get_data_ptr(&(A.storage()[0]));}
//template void * get_array_data_ptr ( array_view & A) { return h5::get_data_ptr(&(A.storage()[0]));}
@@ -76,7 +77,7 @@ namespace triqs { namespace arrays {
* \exception The HDF5 exceptions will be caught and rethrown as TRIQS_RUNTIME_ERROR (with a full stackstrace, cf triqs doc).
*/
template
- void write_array (h5::group g, std::string const & name, array_view const & A, bool C_reorder = true) {
+ void write_array (h5::group g, std::string const & name, array_const_view const & A, bool C_reorder = true) {
static_assert( !std::is_base_of::value, " Not implemented");// 1d is below
if (C_reorder) { write_array(g,name, make_const_cache(A).view(),false); return; }
try {
@@ -90,6 +91,8 @@ namespace triqs { namespace arrays {
template
void write_array (h5::group g, std::string const & name, array const & A, bool C_reorder = true) { write_array(g,name,A(),C_reorder);}
+ template
+ void write_array (h5::group g, std::string const & name, array_view const & A, bool C_reorder = true) { write_array(g,name,A(),C_reorder);}
/*********************************** READ array ****************************************************************/
/**
@@ -102,8 +105,9 @@ namespace triqs { namespace arrays {
* cache of the data to reorder them in memory. If false, the array is stored as it [if you know what you are doing]
* \exception The HDF5 exceptions will be caught and rethrown as TRIQS_RUNTIME_ERROR (with a full stackstrace, cf triqs doc).
*/
- template
- void read_array (h5::group g, std::string const & name, ArrayType & A, bool C_reorder = true) {
+ template
+ void read_array (h5::group g, std::string const & name, ArrayType1 && A, bool C_reorder = true) {
+ typedef typename std::remove_reference::type ArrayType;
static_assert( !std::is_base_of::value, " Not implemented");// 1d is below
typedef typename ArrayType::value_type V;
try {
@@ -127,12 +131,12 @@ namespace triqs { namespace arrays {
}
// overload : special treatment for arrays of strings (one dimension only).
- inline void write_array (h5::group f, std::string const & name, vector_view const & V) {
+ inline void write_array (h5::group f, std::string const & name, vector_const_view V) {
h5::detail::write_1darray_vector_of_string_impl(f,name,V);
}
- inline void write_array (h5::group f, std::string const & name, array_view const & V) {
- write_array(f,name,vector_view(V));
+ inline void write_array (h5::group f, std::string const & name, array_const_view V) {
+ write_array(f,name,vector_const_view(V));
}
inline void read_array (h5::group f, std::string const & name, arrays::vector & V) {
@@ -187,7 +191,7 @@ namespace triqs { namespace arrays {
template
//ENABLE_IF(is_amv_value_or_view_class)
ENABLE_IFC(is_amv_value_or_view_class::value && has_scalar_or_string_value_type::value)
- h5_write (h5::group fg, std::string const & name, ArrayType const & A) { h5_impl::write_array(fg,name, array_view(A));}
+ h5_write (h5::group fg, std::string const & name, ArrayType const & A) { h5_impl::write_array(fg,name, array_const_view(A));}
}}
#endif
diff --git a/triqs/arrays/impl/flags.hpp b/triqs/arrays/impl/flags.hpp
index 8727c6f4..4cf098b7 100644
--- a/triqs/arrays/impl/flags.hpp
+++ b/triqs/arrays/impl/flags.hpp
@@ -36,7 +36,6 @@ namespace triqs { namespace arrays {
// 3 -> Init the array
// 5 -> Boundcheck
- constexpr ull_t ConstView = 1ull << 0;
constexpr ull_t TraversalOrderC = 1ull << 1;
constexpr ull_t TraversalOrderFortran = 1ull << 2;
constexpr ull_t DefaultInit = 1ull << 3;
@@ -55,8 +54,6 @@ namespace triqs { namespace arrays {
constexpr ull_t get(ull_t f, ull_t a) { return ((f & (1ull<> a);}
constexpr ull_t get2(ull_t f, ull_t a) { return ((f & ((1ull<> a);}
- constexpr bool is_const (ull_t f) { return get (f,0) !=0;}
-
#ifdef TRIQS_ARRAYS_ENFORCE_BOUNDCHECK
constexpr bool bound_check (ull_t f) { return true;}
#else
diff --git a/triqs/arrays/impl/indexmap_storage_pair.hpp b/triqs/arrays/impl/indexmap_storage_pair.hpp
index ea6aabcf..0c38835f 100644
--- a/triqs/arrays/impl/indexmap_storage_pair.hpp
+++ b/triqs/arrays/impl/indexmap_storage_pair.hpp
@@ -50,10 +50,10 @@ namespace triqs { namespace arrays {
template class iterator_adapter;
- template struct ISPViewType;
+ template struct ISPViewType;
- template
- class indexmap_storage_pair : Tag::indexmap_storage_pair, TRIQS_CONCEPT_TAG_NAME(MutableCuboidArray) {
+ template
+ class indexmap_storage_pair : Tag::indexmap_storage_pair, TRIQS_CONCEPT_TAG_NAME(MutableCuboidArray) {
public :
typedef typename StorageType::value_type value_type;
@@ -64,7 +64,8 @@ namespace triqs { namespace arrays {
static constexpr unsigned int rank = IndexMapType::domain_type::rank;
static constexpr ull_t opt_flags = OptionFlags;
static constexpr ull_t traversal_order = TraversalOrder;
-
+ static constexpr bool is_const = IsConst;
+
protected:
indexmap_type indexmap_;
@@ -170,13 +171,13 @@ namespace triqs { namespace arrays {
// ------------------------------- operator () --------------------------------------------
- typedef typename ISPViewType::type view_type;
- typedef typename ISPViewType::type weak_view_type;
+ typedef typename ISPViewType::type view_type;
+ typedef typename ISPViewType::type weak_view_type;
// Evaluation and slices
template
typename std::enable_if<
- (!clef::is_any_lazy::value) && (indexmaps::slicer::r_type::domain_type::rank==0) && !flags::is_const(OptionFlags)
+ (!clef::is_any_lazy::value) && (indexmaps::slicer::r_type::domain_type::rank==0) && (!IsConst)
, value_type &>::type
operator()(Args const & ... args) { return storage_[indexmap_(args...)]; }
@@ -191,17 +192,18 @@ namespace triqs { namespace arrays {
//typedef typename std::conditional::type, value_type>::type V2;
typedef value_type V2;
static_assert(IM2::domain_type::rank !=0, "Internal error");
- static constexpr ull_t optmodif = (is_const ? ConstView : 0ull);
- typedef typename ISPViewType::type type;
+ typedef typename ISPViewType::type type;
};
+ // simplify this ?
#ifndef TRIQS_ARRAYS_SLICE_DEFAUT_IS_SHARED
template // non const version
typename boost::lazy_enable_if_c<
- (!clef::is_any_lazy::value) && (indexmaps::slicer::r_type::domain_type::rank!=0) && !flags::is_const(OptionFlags)
+ (!clef::is_any_lazy::value) && (indexmaps::slicer::r_type::domain_type::rank!=0) && (!IsConst)
, result_of_call_as_view
>::type // enable_if
operator()(Args const & ... args) & {
+ // simplify
return typename result_of_call_as_view::type ( indexmaps::slicer::invoke(indexmap_,args...), storage()); }
template // const version
@@ -215,21 +217,21 @@ namespace triqs { namespace arrays {
template // rvalue version : same value of weak as this
typename boost::lazy_enable_if_c<
(!clef::is_any_lazy::value) && (indexmaps::slicer::r_type::domain_type::rank!=0)
- , result_of_call_as_view
+ , result_of_call_as_view
>::type // enable_if
operator()(Args const & ... args) && {
//std::cerr << "slicing a temporary"<< this->storage().is_weak<< result_of_call_as_view::type::storage_type::is_weak << std::endl;
- return typename result_of_call_as_view::type ( indexmaps::slicer::invoke(indexmap_,args...), std::move(storage()));
+ return typename result_of_call_as_view::type ( indexmaps::slicer::invoke(indexmap_,args...), std::move(storage()));
}
/// Equivalent to make_view
- typename ISPViewType::type
+ typename ISPViewType::type
operator()() const & { return *this; }
- typename ISPViewType::type
+ typename ISPViewType::type
operator()() & { return *this; }
- typename ISPViewType::type
+ typename ISPViewType::type
operator()() && { return *this; }
// Interaction with the CLEF library : calling with any clef expression as argument build a new clef expression
diff --git a/triqs/arrays/matrix.hpp b/triqs/arrays/matrix.hpp
index c9eafbe5..2c23ebaf 100644
--- a/triqs/arrays/matrix.hpp
+++ b/triqs/arrays/matrix.hpp
@@ -27,7 +27,7 @@
#include "vector.hpp"
namespace triqs { namespace arrays {
- template class matrix_view;
+ template class matrix_view;
template class matrix;
// ---------------------- matrix --------------------------------
@@ -44,13 +44,14 @@ namespace triqs { namespace arrays {
bool memory_layout_is_fortran() const { return this->indexmap().strides()[0] < this->indexmap().strides()[1]; }
#define IMPL_TYPE indexmap_storage_pair < indexmaps::cuboid::map<2,Opt,TraversalOrder>, \
- storages::shared_block, Opt, TraversalOrder, Tag::matrix_view >
+ storages::shared_block, Opt, TraversalOrder, IsConst, Tag::matrix_view >
- template
+ template
class matrix_view : Tag::matrix_view, TRIQS_CONCEPT_TAG_NAME(MutableMatrix), public IMPL_TYPE {
public :
typedef matrix regular_type;
typedef matrix_view view_type;
+ typedef matrix_view const_view_type;
typedef matrix_view weak_view_type;
typedef typename IMPL_TYPE::indexmap_type indexmap_type;
@@ -94,15 +95,19 @@ namespace triqs { namespace arrays {
//---------------------------------------------------------------------
// this traits is used by indexmap_storage_pair, when slicing to find the correct view type.
- template < class V, int R, ull_t OptionFlags, ull_t To, bool Borrowed >
- struct ISPViewType< V, R, OptionFlags, To, Tag::matrix_view, Borrowed> {
- typedef typename std::conditional , matrix_view >::type type;
+ template < class V, int R, ull_t OptionFlags, ull_t To, bool Borrowed, bool IsConst>
+ struct ISPViewType< V, R, OptionFlags, To, Tag::matrix_view, Borrowed,IsConst> {
+ typedef typename std::conditional,
+ matrix_view>::type type;
};
#undef IMPL_TYPE
+ template
+ using matrix_const_view = matrix_view;
+
// ---------------------- matrix --------------------------------
#define IMPL_TYPE indexmap_storage_pair < indexmaps::cuboid::map<2,Opt,TraversalOrder>, \
- storages::shared_block, Opt, TraversalOrder, Tag::matrix_view >
+ storages::shared_block, Opt, TraversalOrder, false, Tag::matrix_view >
template
class matrix: Tag::matrix, TRIQS_CONCEPT_TAG_NAME(MutableMatrix), public IMPL_TYPE {
@@ -112,6 +117,7 @@ namespace triqs { namespace arrays {
typedef typename IMPL_TYPE::indexmap_type indexmap_type;
typedef matrix regular_type;
typedef matrix_view view_type;
+ typedef matrix_view const_view_type;
typedef matrix_view weak_view_type;
/// Empty matrix.
@@ -215,8 +221,8 @@ namespace triqs { namespace arrays {
// The std::swap is WRONG for a view because of the copy/move semantics of view.
// Use swap instead (the correct one, found by ADL).
namespace std {
- template
- void swap( triqs::arrays::matrix_view & a , triqs::arrays::matrix_view & b)= delete;
+ template
+ void swap( triqs::arrays::matrix_view & a , triqs::arrays::matrix_view & b)= delete;
}
#include "./expression_template/matrix_algebra.hpp"
#endif
diff --git a/triqs/arrays/matrix_tensor_proxy.hpp b/triqs/arrays/matrix_tensor_proxy.hpp
index b185821b..ba697e87 100644
--- a/triqs/arrays/matrix_tensor_proxy.hpp
+++ b/triqs/arrays/matrix_tensor_proxy.hpp
@@ -38,6 +38,8 @@ namespace arrays {
TRIQS_CONCEPT_TAG_NAME(ImmutableCuboidArray)>::type {
typedef typename std::remove_reference::type A_t;
+ static constexpr bool is_const = true;
+
A a;
long n;
@@ -45,8 +47,8 @@ namespace arrays {
typedef indexmaps::slicer slicer_t;
typedef typename slicer_t::r_type indexmap_type;
typedef typename indexmap_type::domain_type domain_type;
- typedef typename std::conditional,
- array_view>::type view_type;
+ typedef typename std::conditional,
+ array_const_view>::type view_type;
template const_matrix_tensor_proxy(AA &&a_, long n_) : a(std::forward(a_)), n(n_) {}
@@ -83,6 +85,8 @@ namespace arrays {
TRIQS_CONCEPT_TAG_NAME(MutableCuboidArray)>::type {
typedef typename std::remove_reference::type A_t;
+ static constexpr bool is_const = false;
+
A a;
long n;
diff --git a/triqs/arrays/vector.hpp b/triqs/arrays/vector.hpp
index 3c6f28f9..d37f8d82 100644
--- a/triqs/arrays/vector.hpp
+++ b/triqs/arrays/vector.hpp
@@ -29,19 +29,20 @@
namespace triqs { namespace arrays {
- template class vector_view;
+ template class vector_view;
template class vector;
// ---------------------- vector_view --------------------------------
-#define IMPL_TYPE indexmap_storage_pair< indexmaps::cuboid::map<1,Opt,0> , storages::shared_block, Opt, 0, Tag::vector_view >
+#define IMPL_TYPE indexmap_storage_pair< indexmaps::cuboid::map<1,Opt,0> , storages::shared_block, Opt, 0, IsConst, Tag::vector_view >
/** */
- template
+ template
class vector_view : Tag::vector_view, TRIQS_CONCEPT_TAG_NAME(MutableVector), public IMPL_TYPE {
public :
typedef vector regular_type;
typedef vector_view view_type;
+ typedef vector_view const_view_type;
typedef vector_view weak_view_type;
typedef typename IMPL_TYPE::indexmap_type indexmap_type;
@@ -95,10 +96,14 @@ namespace triqs { namespace arrays {
};
#undef IMPL_TYPE
- template < class V, int R, ull_t OptionFlags, ull_t To, bool Borrowed >
- struct ISPViewType< V, R,OptionFlags,To, Tag::vector_view, Borrowed> { typedef vector_view type; };
+ template < class V, int R, ull_t OptionFlags, ull_t To, bool Borrowed, bool IsConst>
+ struct ISPViewType< V, R,OptionFlags,To, Tag::vector_view, Borrowed, IsConst> { typedef vector_view type; };
+
+ template
+ using vector_const_view = vector_view;
+
// ---------------------- vector--------------------------------
-#define IMPL_TYPE indexmap_storage_pair< indexmaps::cuboid::map<1,Opt,0> , storages::shared_block, Opt, 0, Tag::vector_view >
+#define IMPL_TYPE indexmap_storage_pair< indexmaps::cuboid::map<1,Opt,0> , storages::shared_block, Opt, 0, false,Tag::vector_view >
template
class vector: Tag::vector, TRIQS_CONCEPT_TAG_NAME(MutableVector), public IMPL_TYPE {
@@ -106,9 +111,10 @@ namespace triqs { namespace arrays {
typedef typename IMPL_TYPE::value_type value_type;
typedef typename IMPL_TYPE::storage_type storage_type;
typedef typename IMPL_TYPE::indexmap_type indexmap_type;
- typedef vector regular_type;
- typedef vector_view view_type;
- typedef vector_view weak_view_type;
+ typedef vector regular_type;
+ typedef vector_view view_type;
+ typedef vector_view const_view_type;
+ typedef vector_view weak_view_type;
/// Empty vector.
vector(){}
@@ -293,7 +299,8 @@ namespace triqs { namespace arrays {
// The std::swap is WRONG for a view because of the copy/move semantics of view.
// Use swap instead (the correct one, found by ADL).
namespace std {
- template void swap( triqs::arrays::vector_view & a , triqs::arrays::vector_view & b)= delete;
+template
+void swap(triqs::arrays::vector_view& a, triqs::arrays::vector_view& b) = delete;
}
#include "./expression_template/vector_algebra.hpp"
diff --git a/triqs/gfs/gf.hpp b/triqs/gfs/gf.hpp
index 0e5d88a2..cf04d737 100644
--- a/triqs/gfs/gf.hpp
+++ b/triqs/gfs/gf.hpp
@@ -479,16 +479,16 @@ namespace triqs { namespace gfs {
// ---------------------------------- slicing ------------------------------------
//slice
- template
- gf_view slice_target (gf_impl const & g, Args&& ... args) {
+ template
+ gf_view slice_target (gf_view g, Args&& ... args) {
static_assert(std::is_same::value, "slice_target only for matrix_valued GF's");
using arrays::range;
//auto sg=slice_target (g.singularity(),range(args,args+1)...);
return gf_view(g.mesh(), g.data()(range(), std::forward(args)... ), slice_target (g.singularity(), std::forward(args)...) , g.symmetry());
}
- template
- gf_view slice_target_to_scalar (gf_impl const & g, Args&& ... args) {
+ template
+ gf_view slice_target_to_scalar (gf_view g, Args&& ... args) {
static_assert(std::is_same::value, "slice_target only for matrix_valued GF's");
using arrays::range;
auto sg=slice_target (g.singularity(),range(args,args+1)...);
@@ -496,8 +496,8 @@ namespace triqs { namespace gfs {
}
// a scalar_valued gf can be viewed as a 1x1 matrix
- template
- gf_view