From 4152f73fcda756d1243f5bb51b050aa9e20408d0 Mon Sep 17 00:00:00 2001
From: Oliver Sander <sander@igpm.rwth-aachen.de>
Date: Fri, 23 Aug 2013 10:25:33 +0200
Subject: [PATCH] Use variadic templates for PushBackTuple and PushFrontTuple,
 if available

The two classes PushBackTuple and PushFrontTuple are both implemented
using a long list of template specializations.  This makes for a lot
of code, and it also limits the maximum tuple size that can be used.
Using variadic templates (FYI: available since gcc-4.3) instead
allows a generic implementation in only a few lines of code, and
only the compiler being the upper limit on tuple size.

An implementation using variadic templates has already been given
in the documentation of PushBackTuple/PushFrontTuple.  This patch
starts to actually use that implementation, provided that
HAVE_VARIADIC_TEMPLATES is set.  Otherwise the old implementation
is used.
---
 dune/common/tupleutility.hh | 38 ++++++++++++++++---------------------
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/dune/common/tupleutility.hh b/dune/common/tupleutility.hh
index 9e2327fa2..9fd019de5 100644
--- a/dune/common/tupleutility.hh
+++ b/dune/common/tupleutility.hh
@@ -1572,17 +1572,6 @@ namespace Dune {
    *
    * \tparam Tuple The tuple type to extend
    * \tparam T     The type to be appended to the tuple
-   *
-   * With variadic templates the generic specialization would be:
-   *
-   * \code
-   * template<class... TupleArgs, class T>
-   * struct PushBackTuple<typename Dune::tuple<TupleArgs...>, T>
-   * {
-   *   typedef typename Dune::tuple<TupleArgs..., T> type;
-   * };
-   * \endcode
-   *
    */
   template< class Tuple, class T>
   struct PushBackTuple
@@ -1607,6 +1596,13 @@ namespace Dune {
 
 #ifndef DOXYGEN
 
+#if HAVE_VARIADIC_TEMPLATES
+  template<class... TupleArgs, class T>
+  struct PushBackTuple<typename Dune::tuple<TupleArgs...>, T>
+  {
+    typedef typename Dune::tuple<TupleArgs..., T> type;
+  };
+#else
   template<class T>
   struct PushBackTuple< Dune::tuple<>, T>
   {
@@ -1660,6 +1656,7 @@ namespace Dune {
   {
     typedef typename Dune::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T> type;
   };
+#endif  // HAVE_VARIADIC_TEMPLATES
 
 #endif
 
@@ -1670,17 +1667,6 @@ namespace Dune {
    *
    * \tparam Tuple The tuple type to extend
    * \tparam T     The type to be prepended to the tuple
-   *
-   * With variadic templates the generic specialization would be:
-   *
-   * \code
-   * template<class... TupleArgs, class T>
-   * struct PushFrontTuple<typename Dune::tuple<TupleArgs...>, T>
-   * {
-   *   typedef typename Dune::tuple<T, TupleArgs...> type;
-   * };
-   * \endcode
-   *
    */
   template< class Tuple, class T>
   struct PushFrontTuple
@@ -1705,6 +1691,13 @@ namespace Dune {
 
 #ifndef DOXYGEN
 
+#if HAVE_VARIADIC_TEMPLATES
+  template<class... TupleArgs, class T>
+  struct PushFrontTuple<typename Dune::tuple<TupleArgs...>, T>
+  {
+    typedef typename Dune::tuple<T, TupleArgs...> type;
+  };
+#else
   template<class T>
   struct PushFrontTuple< Dune::tuple<>, T>
   {
@@ -1758,6 +1751,7 @@ namespace Dune {
   {
     typedef typename Dune::tuple<T, T1, T2, T3, T4, T5, T6, T7, T8> type;
   };
+#endif //  HAVE_VARIADIC_TEMPLATES
 
 #endif
 
-- 
GitLab