[libsigcplusplus/c++17] C++17: limmit_trackable_target: Use constexpr if to simplify code.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsigcplusplus/c++17] C++17: limmit_trackable_target: Use constexpr if to simplify code.
- Date: Thu, 7 Jul 2016 20:47:27 +0000 (UTC)
commit 50b30c74b5f13a133776f928f3b70674046f3cfe
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Jul 7 22:36:07 2016 +0200
C++17: limmit_trackable_target: Use constexpr if to simplify code.
sigc++/visit_each.h | 28 ++++------------------------
1 files changed, 4 insertions(+), 24 deletions(-)
---
diff --git a/sigc++/visit_each.h b/sigc++/visit_each.h
index e28d385..0602f07 100644
--- a/sigc++/visit_each.h
+++ b/sigc++/visit_each.h
@@ -42,10 +42,11 @@ struct limit_trackable_target
template <typename T_type>
void operator()(T_type&& type) const
{
- using T_self = limit_trackable_target<T_action>;
-
//Only call action_() if T_Type derives from trackable.
- with_type<T_type, T_self>::execute_(std::forward<T_type>(type), *this);
+ constexpr bool derived = is_base_of_or_same_v<sigc::trackable, T_type>;
+ if constexpr(derived == true) {
+ action_(type);
+ }
}
explicit limit_trackable_target(const T_action& action) : action_(action) {}
@@ -56,27 +57,6 @@ struct limit_trackable_target
limit_trackable_target& operator=(limit_trackable_target&& src) = delete;
T_action action_;
-
-private:
- template <typename T_type, typename T_limit, bool I_derived = is_base_of_or_same_v<sigc::trackable,
T_type>>
- struct with_type;
-
- // Specialization for I_derived = false
- template <typename T_type, typename T_limit>
- struct with_type<T_type, T_limit, false>
- {
- static void execute_(const T_type&, const T_limit&) {}
- };
-
- // Specialization for I_derived = true
- template <typename T_type, typename T_limit>
- struct with_type<T_type, T_limit, true>
- {
- static void execute_(const T_type& type, const T_limit& action)
- {
- action.action_(type);
- }
- };
};
} /* namespace internal */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]