From 9e3027e5f771c231c7ad9ae869e68cc3e48036ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20Gr=C3=A4ser?= <graeser@dune-project.org> Date: Mon, 14 Nov 2016 16:27:28 +0100 Subject: [PATCH] [test] Check Std::apply() by implementing a tuple transformation This checks with a real application example: An implementation of a tuple transformation. Maybe we also want to implement our real tuple tranformation that way, because its easier to read and much shorter. --- dune/common/test/stdapplytest.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dune/common/test/stdapplytest.cc b/dune/common/test/stdapplytest.cc index ccf2370c3..d45169446 100644 --- a/dune/common/test/stdapplytest.cc +++ b/dune/common/test/stdapplytest.cc @@ -46,6 +46,17 @@ int main() test.check(std::get<0>(intTuple) == intTuple0) << "Dune::Std::apply does not properly return references"; + // transformTuple implemented using Std::apply + auto transformTuple = [](auto&& t, auto&& f) { + return Dune::Std::apply([&](auto&&... args) { + return std::make_tuple((f(std::forward<decltype(args)>(args)))...); + }, t); + }; + + auto t1 = std::make_tuple(1, 0.2); + auto t2 = transformTuple(t1, [](auto&& x) { return 1.0/x; }); + + test.check(t2 == std::make_tuple(1.0, 5.0)) << "transformTuple implementation based on Dune::Std::apply fails"; return test.exit(); } -- GitLab