Skip to content
Snippets Groups Projects
Commit df037802 authored by Martin Nolte's avatar Martin Nolte
Browse files

[bugfix] make AddRefTypeEvaluator work in tranformTuple

As documented, tranformTuple should support AddRefTypeEvaluator. As
std::make_tuple will remove references (using std::decay) from the
funtor's return type, the returned tuple would contain copies of the
values. This is not the intended behavior.

This patch adds AddRefTypeEvaluator to the utilitytest and fixes the
return type of transformTuple.
parent d7be1c5c
No related branches found
No related tags found
No related merge requests found
......@@ -27,7 +27,6 @@ struct Counter {
int result_;
};
int main(int, char**)
{
......@@ -59,6 +58,7 @@ int main(int, char**)
long l = 4;
char c = 's';
typedef std::tuple<int,char,long,char> Tuple1;
typedef std::tuple<int&,char&,long&,char&> RefTuple1;
typedef std::tuple<int*,char*,long*,char*> PointerTuple1;
static_assert((std::is_same<PointerTuple1,
......@@ -67,7 +67,9 @@ int main(int, char**)
"RefTuple1 with added pointers should be the same as "
"PointerTuple1, but it isn't!");
Tuple1 t1(i,c,l,c);
RefTuple1 refs(i, c, l, c);
DUNE_UNUSED RefTuple1 refs2(Dune::transformTuple<Dune::AddRefTypeEvaluator>(t1));
PointerTuple1 pointers1
(Dune::transformTuple<Dune::AddPtrTypeEvaluator>(refs));
if(&i != std::get<0>(pointers1) || &c != std::get<1>(pointers1) ||
......
......@@ -79,10 +79,10 @@ namespace Dune {
#ifndef DOXYGEN
template<class Tuple, class Functor, std::size_t... I>
inline auto genericTransformTupleBackendImpl(Tuple& t, Functor& f, const Std::index_sequence<I...>& ) ->
decltype(std::make_tuple(f(std::get<I>(t))...)) const
inline auto genericTransformTupleBackendImpl(Tuple& t, Functor& f, const Std::index_sequence<I...>& )
-> std::tuple<decltype(f(std::get<I>(t)))...>
{
return std::make_tuple(f(std::get<I>(t))...);
return std::tuple<decltype(f(std::get<I>(t)))...>(f(std::get<I>(t))...);
}
template<class... Args, class Functor>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment