From 0586c77307f3c9ab0c4606fa4919b239e781bf6d Mon Sep 17 00:00:00 2001 From: Olivier Parcollet Date: Wed, 11 Sep 2013 20:22:38 +0200 Subject: [PATCH] add c14 details in std::c14 - to use already a few c14 convenience details : -> polymorphic std::plus, e.g. boost::mpi::reduce (world, A,C, std::c14::plus<>(),0); this plus determine the type by itself ... -> errors on the type can be very cryptic on the gf. -> add std::c14::make_unique (equivalent of make_shared for unique_ptr). --- test/triqs/arrays/array_mpi.cpp | 3 ++- triqs/utility/c14.hpp | 47 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 triqs/utility/c14.hpp diff --git a/test/triqs/arrays/array_mpi.cpp b/test/triqs/arrays/array_mpi.cpp index 40f7545c..34276568 100644 --- a/test/triqs/arrays/array_mpi.cpp +++ b/test/triqs/arrays/array_mpi.cpp @@ -24,6 +24,7 @@ #include #include #include +#include using std::cout; using std::endl; using namespace triqs::arrays; @@ -43,7 +44,7 @@ int main(int argc, char* argv[]) if (world.rank() ==0) std::cout<<" A = "< >(),0); + boost::mpi::reduce (world, A,C, std::c14::plus<>(),0); int s= world.size(); if (world.rank() ==0) std::cout<<" C = "<( (s*(s+1)/2) * A) <. + * + ******************************************************************************/ +#ifndef TRIQS_C14_FIX_H +#define TRIQS_C14_FIX_H +#include +#include + +// a few that will be C++14, use in advance.... + +namespace std { + namespace c14 { + + // use simply std::c14::plus<>() ... + template struct plus: std::plus{}; + + template<> struct plus { + template + auto operator()( T&& t, U&& u) const DECL_AND_RETURN(std::forward(t) + std::forward(u)); + }; + + template + std::unique_ptr make_unique(Args&&... args) { return std::unique_ptr(new T(std::forward(args)...)); } + + } +} + + +#endif +