]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
denc: Simplify is_any_of
authorAdam C. Emerson <aemerson@redhat.com>
Tue, 9 Jan 2018 21:15:34 +0000 (16:15 -0500)
committerAdam C. Emerson <aemerson@redhat.com>
Fri, 12 Jan 2018 04:50:06 +0000 (23:50 -0500)
We can't simplify underlying type in the obvious way since template
evaluation is strict.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/include/denc.h

index 3cc31234f5b0fa8927f3b75861d449e0ed6f7bdf..b4b133a8460d6f36e312a4a6957b87e940be064f 100644 (file)
@@ -54,6 +54,9 @@ struct denc_traits {
   static constexpr bool need_contiguous = true;
 };
 
+template<typename T>
+inline constexpr bool denc_supported = denc_traits<T>::supported;
+
 
 // hack for debug only; FIXME
 //#include <iostream>
@@ -69,7 +72,7 @@ struct denc_traits {
 //#define ENCODE_DUMP_PATH /tmp/something
 
 #ifdef ENCODE_DUMP_PATH
-# include <stdio.h>
+# include <cstdio>
 # include <sys/types.h>
 # include <sys/stat.h>
 # include <fcntl.h>
@@ -224,16 +227,8 @@ struct denc_traits {
 // ---------------------------------------------------------------------
 // raw types
 namespace _denc {
-template<class T, class...>
-struct is_any_of : std::false_type {};
-template<class T, class Head, class... Tail>
-struct is_any_of<T, Head, Tail...> : std::conditional<
-  std::is_same<T, Head>::value,
-  std::true_type,
-  is_any_of<T, Tail...>>::type
-{};
 template<typename T, typename... Us>
-inline constexpr bool is_any_of_v = is_any_of<T, Us...>::value;
+inline constexpr bool is_any_of = (... || std::is_same_v<T, Us>);
 
 template<typename T, typename=void> struct underlying_type {
   using type = T;
@@ -251,8 +246,8 @@ template<typename T>
 struct denc_traits<
   T,
   std::enable_if_t<
-    _denc::is_any_of_v<_denc::underlying_type_t<T>,
-                      ceph_le64, ceph_le32, ceph_le16, uint8_t
+    _denc::is_any_of<_denc::underlying_type_t<T>,
+                    ceph_le64, ceph_le32, ceph_le16, uint8_t
 #ifndef _CHAR_IS_SIGNED
                       , int8_t
 #endif