/******************************************************************************* * * 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 . * ******************************************************************************/ #ifndef TRIQS_UTILITY_FACTORY_H #define TRIQS_UTILITY_FACTORY_H #include #include #include "./macros.hpp" #include "./std_vector_expr_template.hpp" namespace triqs { namespace utility { template struct factories { template < typename U> static T invoke( U && x) { return T(std::forward(x));} }; template struct factories >{ typedef std::vector R; static R invoke(R && x) { return R(std::move(x));} static R invoke(R const & x) { return R(x);} static R invoke(R & x) { return R(x);} template static R invoke( std::vector && v) { static_assert(std::is_constructible::value, "Cannot make std::vector from std::vector"); R r; r.reserve(v.size()); for (auto & x : v) r.push_back(std::move(x)); return r; } template static TYPE_ENABLE_IF(R,ImmutableStdVector) invoke( VectorType & v) { static_assert(std::is_constructible::value, "Cannot make std::vector from the proposed type"); R r; r.reserve(v.size()); for(size_t i=0; i static R invoke( std::vector const & v) { static_assert(std::is_constructible::value, "Cannot make std::vector from std::vector"); R r; r.reserve(v.size()); for (auto & x : v) r.push_back(T(x)); return r; } */ }; template T factory(U && ... x) { return factories::invoke(std::forward(x)...);} // redondant : done with x =factory(x) // /* template struct gal_assign { template < typename U> static void invoke(T & x, U && y) { x = std::forward(y);} }; template struct gal_assign> { typedef std::vector R; static void invoke(R & x, R && y) { x=std::move(y);} static void invoke(R & x, R const & y) { x=y;} template static R invoke( R &r, std::vector && v) { static_assert(std::is_constructible::value, "Cannot assign std::vector && -> std::vector"); r.clear(); r.reserve(v.size()); for (auto & x : v) r.push_back(std::move(x)); } template static R invoke( R &r, std::vector const & v) { static_assert(std::is_constructible::value, "Cannot assign std::vector const & -> std::vector"); r.clear(); r.reserve(v.size()); for (auto & x : v) r.push_back(x); } }; */ }}//namespace triqs #endif