[libsigc++2/variadic_bind2: 60/68] Use tuple_for_each() instead of (now unnecessary) tuple_for_each_const().



commit 3e161409cd7ce07cd6c50770f9b64d55d84dd318
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Feb 19 11:28:14 2016 +0100

    Use tuple_for_each() instead of (now unnecessary) tuple_for_each_const().

 sigc++/adaptors/bind.h        |    4 +-
 sigc++/adaptors/track_obj.h   |    4 +-
 sigc++/filelist.am            |    2 +-
 sigc++/tuple_for_each.h       |   82 +++++++++++++++++++++++++++++++++++++++++
 sigc++/tuple_for_each_const.h |   76 --------------------------------------
 5 files changed, 87 insertions(+), 81 deletions(-)
---
diff --git a/sigc++/adaptors/bind.h b/sigc++/adaptors/bind.h
index b671021..00b0bf8 100644
--- a/sigc++/adaptors/bind.h
+++ b/sigc++/adaptors/bind.h
@@ -6,7 +6,7 @@
 #include <sigc++/tuple_start.h>
 #include <sigc++/tuple_end.h>
 #include <sigc++/tuple_transform_each.h>
-#include <sigc++/tuple_for_each_const.h>
+#include <sigc++/tuple_for_each.h>
 
 //TODO: See comment in functor_trait.h.
 #if defined(nil) && defined(SIGC_PRAGMA_PUSH_POP_MACRO)
@@ -266,7 +266,7 @@ struct visitor<bind_functor<-1, T_functor, T_type...> >
   {
     sigc::visit_each(_A_action, _A_target.functor_);
 
-    sigc::tuple_for_each_const<TupleVisitorVisitEach>(_A_target.bound_, _A_action);
+    sigc::tuple_for_each<TupleVisitorVisitEach>(_A_target.bound_, _A_action);
   }
 };
 #endif //DOXYGEN_SHOULD_SKIP_THIS
diff --git a/sigc++/adaptors/track_obj.h b/sigc++/adaptors/track_obj.h
index e454f9e..2816054 100644
--- a/sigc++/adaptors/track_obj.h
+++ b/sigc++/adaptors/track_obj.h
@@ -3,7 +3,7 @@
 
 #include <sigc++/adaptors/adaptor_trait.h>
 #include <sigc++/limit_reference.h>
-#include <sigc++/tuple_for_each_const.h>
+#include <sigc++/tuple_for_each.h>
 
 namespace sigc {
 
@@ -111,7 +111,7 @@ struct visitor<track_obj_functor<T_functor, T_obj...>>
 
     //Call sigc::visit_each(_A_action, element) on each element in the 
     //_A_target.obj_ tuple:
-    sigc::tuple_for_each_const<TrackObjVisitForEach>(_A_target.obj_, _A_action);
+    sigc::tuple_for_each<TrackObjVisitForEach>(_A_target.obj_, _A_action);
   }
 
 private:
diff --git a/sigc++/filelist.am b/sigc++/filelist.am
index 581496b..f02f6c2 100644
--- a/sigc++/filelist.am
+++ b/sigc++/filelist.am
@@ -54,7 +54,7 @@ sigc_public_h =                               \
        tuple_cat.h \
        tuple_cdr.h \
        tuple_end.h \
-       tuple_for_each_const.h \
+       tuple_for_each.h \
        tuple_start.h \
        tuple_transform_each.h \
        type_traits.h                   \
diff --git a/sigc++/tuple_for_each.h b/sigc++/tuple_for_each.h
new file mode 100644
index 0000000..1f74a41
--- /dev/null
+++ b/sigc++/tuple_for_each.h
@@ -0,0 +1,82 @@
+/* Copyright (C) 2016 Murray Cumming
+ *
+ * This program 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.
+ *
+ * This program 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 this program.  If not, see <http://www.gnu.org/licenses/
+ */
+
+#ifndef MURRAYC_TUPLE_UTILS_TUPLE_FOR_EACH_H
+#define MURRAYC_TUPLE_UTILS_TUPLE_FOR_EACH_H
+
+#include <tuple>
+
+namespace sigc {
+
+namespace detail {
+
+template <template <typename> class T_visitor, std::size_t index,
+  typename... T_extras>
+struct tuple_for_each_impl {
+  template <typename T>
+  static void
+  tuple_for_each(T&& t, T_extras&&... extras) {
+    using element_type = typename std::tuple_element<index, std::decay_t<T>>::type;
+    T_visitor<element_type>::visit(std::get<index>(t), std::forward<T_extras>(extras)...);
+
+    tuple_for_each_impl<T_visitor, index - 1, T_extras...>::tuple_for_each(
+      std::forward<T>(t), std::forward<T_extras>(extras)...);
+  }
+};
+
+template <template <typename> class T_visitor, typename... T_extras>
+struct tuple_for_each_impl<T_visitor, 0, T_extras...> {
+  template <typename T>
+  static void
+  tuple_for_each(T&& t, T_extras&&... extras) {
+    constexpr std::size_t index = 0;
+
+    using element_type = typename std::tuple_element<index, std::decay_t<T>>::type;
+    T_visitor<element_type>::visit(std::get<index>(std::forward<T>(t)), std::forward<T_extras>(extras)...);
+  }
+};
+
+} // detail namespace
+
+
+/**
+ * Get a tuple with each element having the transformed value of the element
+ * in the original tuple.
+ *
+ * @tparam T_visitor should be a template that has a static visit() method.
+ * @tparam T the tuple type.
+ * @tparam T_extras the types of any extra arguments to pass to @e T_Visitor's
+ * visit() method.
+ * @param t The tuple whose elements should be visited.
+ * @param extras Any extra arguments to pass to @e T_Visitor's visit() method.
+ */
+template <template <typename> class T_visitor, typename T, typename... T_extras>
+void
+tuple_for_each(T&& t, T_extras&&... extras) {
+  //We use std::decay_t<> because tuple_size is not defined for references.
+  constexpr auto size = std::tuple_size<std::decay_t<T>>::value;
+
+  if(size == 0) {
+    return;
+  }
+
+  detail::tuple_for_each_impl<T_visitor, size - 1, T_extras...>::tuple_for_each(
+    std::forward<T>(t), std::forward<T_extras>(extras)...);
+}
+
+} // namespace sigc
+
+#endif //MURRAYC_TUPLE_UTILS_TUPLE_FOR_EACH_H


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]