/*******************************************************************************
*
* TRIQS: a Toolbox for Research in Interacting Quantum Systems
*
* Copyright (C) 2011 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 .
*
******************************************************************************/
#ifndef TRIQS_ARRAYS_MAKE_IMMUTABLE_ARRAY_H
#define TRIQS_ARRAYS_MAKE_IMMUTABLE_ARRAY_H
#include "./array.hpp"
#include "../utility/tuple_tools.hpp"
namespace triqs { namespace arrays {
template
class immutable_array_expr_impl : TRIQS_CONCEPT_TAG_NAME(ImmutableArray) {
template struct _si { typedef size_t type;};
public :
immutable_array_expr_impl(Expr e_, clef::pair ... p):
f(clef::make_function(e_, clef::placeholder()...)), dom_(make_shape(p.rhs().size()...)) {};
typedef typename triqs::clef::result_of::make_function... >::type function_type;
typedef typename std::result_of::type...)>::type value_type;
typedef indexmaps::cuboid::domain_t domain_type;
domain_type domain() const { return dom_;}
template value_type operator() (Args const & ... args) const { return f(args...); }
friend std::ostream & operator<<(std::ostream & out, immutable_array_expr_impl const & x){return out<<" immutable_array on domain : "<
immutable_array_expr_impl make_immutable_array( Expr const & expr, clef::pair ... p) {
return immutable_array_expr_impl (expr, p...);
}
// if ones prefers to use a function...
template
class immutable_array_fun_impl : TRIQS_CONCEPT_TAG_NAME(ImmutableArray) {
template struct _si { typedef size_t type;};
public :
immutable_array_fun_impl(Function f, Ranges ... r) : f_(std::move(f)), dom_(make_shape(r.size()...)) {};
//typedef typename std::function::result_type value_type;
typedef decltype( triqs::tuple::apply(std::declval(),std::make_tuple(typename Ranges::index_type()...))) value_type;
typedef indexmaps::cuboid::domain_t domain_type;
domain_type domain() const { return dom_;}
template value_type operator() (Args const & ... args) const { return f_(args...); }
friend std::ostream & operator<<(std::ostream & out, immutable_array_fun_impl const & x){return out<<" immutable_array on domain : "<
immutable_array_fun_impl make_immutable_array(Function f, Ranges ... r) {
return immutable_array_fun_impl (std::move(f), r...);
}
}}//namespace triqs::arrays
#endif