mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ti...@apache.org
Subject mesos git commit: Constrained types used in Flags instantiation.
Date Wed, 13 Jan 2016 12:57:23 GMT
Repository: mesos
Updated Branches:
  refs/heads/master 1f01b7ab4 -> dcf83a5aa


Constrained types used in Flags instantiation.

To make the implementation less repetitive reimplemented `FlagsBase`
with a variadic template; this allows to now use an arbitrary number of
`FlagsBase` bases.

Since `Flags<>` does already inherit virtually from `FlagsBase` it
should be a safer base class than `FlagsBase` for users.

Review: https://reviews.apache.org/r/41882/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/dcf83a5a
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/dcf83a5a
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/dcf83a5a

Branch: refs/heads/master
Commit: dcf83a5aa8b85152199806448f773598c121db5c
Parents: 1f01b7a
Author: Benjamin Bannier <benjamin.bannier@mesosphere.io>
Authored: Wed Jan 13 13:27:47 2016 +0100
Committer: Till Toenshoff <toenshoff@me.com>
Committed: Wed Jan 13 13:27:47 2016 +0100

----------------------------------------------------------------------
 .../stout/include/stout/flags/flags.hpp         | 40 +++++++++-----------
 1 file changed, 18 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/dcf83a5a/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp
index addef78..2a18845 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/flags/flags.hpp
@@ -17,6 +17,8 @@
 #include <map>
 #include <ostream>
 #include <string>
+#include <tuple>
+#include <type_traits>
 #include <typeinfo> // For typeid.
 #include <vector>
 
@@ -237,28 +239,22 @@ private:
 };
 
 
-// Need to declare/define some explicit subclasses of FlagsBase so
-// that we can overload the 'Flags::operator FlagsN() const'
-// functions for each possible type.
-class _Flags1 : public virtual FlagsBase {};
-class _Flags2 : public virtual FlagsBase {};
-class _Flags3 : public virtual FlagsBase {};
-class _Flags4 : public virtual FlagsBase {};
-class _Flags5 : public virtual FlagsBase {};
-
-
-// TODO(benh): Add some "type constraints" for template parameters to
-// make sure they are all of type FlagsBase.
-template <typename Flags1 = _Flags1,
-          typename Flags2 = _Flags2,
-          typename Flags3 = _Flags3,
-          typename Flags4 = _Flags4,
-          typename Flags5 = _Flags5>
-class Flags : public virtual Flags1,
-              public virtual Flags2,
-              public virtual Flags3,
-              public virtual Flags4,
-              public virtual Flags5 {};
+template <typename... FlagsTypes>
+class Flags : public virtual FlagsTypes...
+{
+  // Construct tuple types of sizeof...(FlagsTypes) compile-time bools to check
+  // non-recursively that all FlagsTypes derive from FlagsBase; as a helper we
+  // use is_object<FlagTypes> to construct sizeof...(FlagTypes) true types for
+  // the RHS (is_object<T> is a true type for anything one would inherit from).
+  static_assert(
+    std::is_same<
+      std::tuple<typename std::is_base_of<FlagsBase, FlagsTypes>::type...>,
+      std::tuple<typename std::is_object<FlagsTypes>::type...>>::value,
+    "Can only instantiate Flags with FlagsBase types.");
+};
+
+template <>
+class Flags<> : public virtual FlagsBase {};
 
 
 template <typename T1, typename T2, typename F>


Mime
View raw message