folly: fix clang's -Wundefined-var-template
[folly.git] / folly / Traits.h
index caeb852c3b6f3d85949398331b3a00be9a5bb9e2..39136a72d8cb3ea862fab04b39f9e0dfecacf946 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,8 +16,7 @@
 
 // @author: Andrei Alexandrescu
 
-#ifndef FOLLY_BASE_TRAITS_H_
-#define FOLLY_BASE_TRAITS_H_
+#pragma once
 
 #include <memory>
 #include <limits>
@@ -38,9 +37,7 @@
 #endif
 
 #include <boost/type_traits.hpp>
-#include <boost/mpl/and.hpp>
 #include <boost/mpl/has_xxx.hpp>
-#include <boost/mpl/not.hpp>
 
 namespace folly {
 
@@ -133,6 +130,25 @@ template <class T> struct IsZeroInitializable
       traits_detail::has_true_IsZeroInitializable<T>::value
     > {};
 
+template <typename...>
+struct Conjunction : std::true_type {};
+template <typename T>
+struct Conjunction<T> : T {};
+template <typename T, typename... TList>
+struct Conjunction<T, TList...>
+    : std::conditional<T::value, Conjunction<TList...>, T>::type {};
+
+template <typename...>
+struct Disjunction : std::false_type {};
+template <typename T>
+struct Disjunction<T> : T {};
+template <typename T, typename... TList>
+struct Disjunction<T, TList...>
+    : std::conditional<T::value, T, Disjunction<TList...>>::type {};
+
+template <typename T>
+struct Negation : std::integral_constant<bool, !T::value> {};
+
 } // namespace folly
 
 /**
@@ -271,8 +287,9 @@ template <class T> class shared_ptr;
 
 template <class T, class U>
 struct has_nothrow_constructor< std::pair<T, U> >
-    : ::boost::mpl::and_< has_nothrow_constructor<T>,
-                          has_nothrow_constructor<U> > {};
+    : std::integral_constant<bool,
+        has_nothrow_constructor<T>::value &&
+        has_nothrow_constructor<U>::value> {};
 
 } // namespace boost
 
@@ -280,8 +297,10 @@ namespace folly {
 
 // STL commonly-used types
 template <class T, class U>
-struct IsRelocatable<  std::pair<T, U> >
-    : ::boost::mpl::and_< IsRelocatable<T>, IsRelocatable<U> > {};
+struct IsRelocatable< std::pair<T, U> >
+    : std::integral_constant<bool,
+        IsRelocatable<T>::value &&
+        IsRelocatable<U>::value> {};
 
 // Is T one of T1, T2, ..., Tn?
 template <class T, class... Ts>
@@ -318,10 +337,13 @@ struct is_negative_impl<T, false> {
 
 // folly::to integral specializations can end up generating code
 // inside what are really static ifs (not executed because of the templated
-// types) that violate -Wsign-compare so suppress them in order to not prevent
-// all calling code from using it.
+// types) that violate -Wsign-compare and/or -Wbool-compare so suppress them
+// in order to not prevent all calling code from using it.
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wsign-compare"
+#if __GNUC_PREREQ(5, 0)
+#pragma GCC diagnostic ignored "-Wbool-compare"
+#endif
 
 template <typename RHS, RHS rhs, typename LHS>
 bool less_than_impl(LHS const lhs) {
@@ -331,8 +353,6 @@ bool less_than_impl(LHS const lhs) {
     lhs < rhs;
 }
 
-#pragma GCC diagnostic pop
-
 template <typename RHS, RHS rhs, typename LHS>
 bool greater_than_impl(LHS const lhs) {
   return
@@ -341,6 +361,8 @@ bool greater_than_impl(LHS const lhs) {
     lhs > rhs;
 }
 
+#pragma GCC diagnostic pop
+
 } // namespace detail {
 
 // same as `x < 0`
@@ -377,9 +399,19 @@ bool greater_than(LHS const lhs) {
   >(lhs);
 }
 
+/**
+ * Like std::piecewise_construct, a tag type & instance used for in-place
+ * construction of non-movable contained types, e.g. by Synchronized.
+ */
+struct construct_in_place_t {};
+constexpr construct_in_place_t construct_in_place{};
+
 } // namespace folly
 
+// gcc-5.0 changed string's implementation in libgcc to be non-relocatable
+#if __GNUC__ < 5
 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(std::basic_string);
+#endif
 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::vector);
 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::list);
 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::deque);
@@ -471,5 +503,3 @@ FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(boost::shared_ptr);
       classname, func_name, /* nolint */ volatile); \
   FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL( \
       classname, func_name, /* nolint */ volatile const)
-
-#endif //FOLLY_BASE_TRAITS_H_