Promote aligned_malloc and aligned_free
[folly.git] / folly / Traits.h
1 /*
2  * Copyright 2017 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 // @author: Andrei Alexandrescu
18
19 #pragma once
20
21 #include <functional>
22 #include <limits>
23 #include <memory>
24 #include <type_traits>
25
26 #include <folly/Portability.h>
27
28 // libc++ doesn't provide this header, nor does msvc
29 #ifdef FOLLY_HAVE_BITS_CXXCONFIG_H
30 // This file appears in two locations: inside fbcode and in the
31 // libstdc++ source code (when embedding fbstring as std::string).
32 // To aid in this schizophrenic use, two macros are defined in
33 // c++config.h:
34 //   _LIBSTDCXX_FBSTRING - Set inside libstdc++.  This is useful to
35 //      gate use inside fbcode v. libstdc++
36 #include <bits/c++config.h>
37 #endif
38
39 #define FOLLY_CREATE_HAS_MEMBER_TYPE_TRAITS(classname, type_name)              \
40   template <typename TTheClass_>                                               \
41   struct classname##__folly_traits_impl__ {                                    \
42     template <typename UTheClass_>                                             \
43     static constexpr bool test(typename UTheClass_::type_name*) {              \
44       return true;                                                             \
45     }                                                                          \
46     template <typename>                                                        \
47     static constexpr bool test(...) {                                          \
48       return false;                                                            \
49     }                                                                          \
50   };                                                                           \
51   template <typename TTheClass_>                                               \
52   using classname = typename std::conditional<                                 \
53       classname##__folly_traits_impl__<TTheClass_>::template test<TTheClass_>( \
54           nullptr),                                                            \
55       std::true_type,                                                          \
56       std::false_type>::type;
57
58 #define FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, cv_qual) \
59   template <typename TTheClass_, typename RTheReturn_, typename... TTheArgs_> \
60   struct classname##__folly_traits_impl__<                                    \
61       TTheClass_,                                                             \
62       RTheReturn_(TTheArgs_...) cv_qual> {                                    \
63     template <                                                                \
64         typename UTheClass_,                                                  \
65         RTheReturn_ (UTheClass_::*)(TTheArgs_...) cv_qual>                    \
66     struct sfinae {};                                                         \
67     template <typename UTheClass_>                                            \
68     static std::true_type test(sfinae<UTheClass_, &UTheClass_::func_name>*);  \
69     template <typename>                                                       \
70     static std::false_type test(...);                                         \
71   }
72
73 /*
74  * The FOLLY_CREATE_HAS_MEMBER_FN_TRAITS is used to create traits
75  * classes that check for the existence of a member function with
76  * a given name and signature. It currently does not support
77  * checking for inherited members.
78  *
79  * Such classes receive two template parameters: the class to be checked
80  * and the signature of the member function. A static boolean field
81  * named `value` (which is also constexpr) tells whether such member
82  * function exists.
83  *
84  * Each traits class created is bound only to the member name, not to
85  * its signature nor to the type of the class containing it.
86  *
87  * Say you need to know if a given class has a member function named
88  * `test` with the following signature:
89  *
90  *    int test() const;
91  *
92  * You'd need this macro to create a traits class to check for a member
93  * named `test`, and then use this traits class to check for the signature:
94  *
95  * namespace {
96  *
97  * FOLLY_CREATE_HAS_MEMBER_FN_TRAITS(has_test_traits, test);
98  *
99  * } // unnamed-namespace
100  *
101  * void some_func() {
102  *   cout << "Does class Foo have a member int test() const? "
103  *     << boolalpha << has_test_traits<Foo, int() const>::value;
104  * }
105  *
106  * You can use the same traits class to test for a completely different
107  * signature, on a completely different class, as long as the member name
108  * is the same:
109  *
110  * void some_func() {
111  *   cout << "Does class Foo have a member int test()? "
112  *     << boolalpha << has_test_traits<Foo, int()>::value;
113  *   cout << "Does class Foo have a member int test() const? "
114  *     << boolalpha << has_test_traits<Foo, int() const>::value;
115  *   cout << "Does class Bar have a member double test(const string&, long)? "
116  *     << boolalpha << has_test_traits<Bar, double(const string&, long)>::value;
117  * }
118  *
119  * @author: Marcelo Juchem <marcelo@fb.com>
120  */
121 #define FOLLY_CREATE_HAS_MEMBER_FN_TRAITS(classname, func_name)               \
122   template <typename, typename>                                               \
123   struct classname##__folly_traits_impl__;                                    \
124   FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, );             \
125   FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, const);        \
126   FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(                                     \
127       classname, func_name, /* nolint */ volatile);                           \
128   FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(                                     \
129       classname, func_name, /* nolint */ volatile const);                     \
130   template <typename TTheClass_, typename TTheSignature_>                     \
131   using classname =                                                           \
132       decltype(classname##__folly_traits_impl__<TTheClass_, TTheSignature_>:: \
133                    template test<TTheClass_>(nullptr))
134
135 namespace folly {
136
137 /***
138  *  _t
139  *
140  *  Instead of:
141  *
142  *    using decayed = typename std::decay<T>::type;
143  *
144  *  With the C++14 standard trait aliases, we could use:
145  *
146  *    using decayed = std::decay_t<T>;
147  *
148  *  Without them, we could use:
149  *
150  *    using decayed = _t<std::decay<T>>;
151  *
152  *  Also useful for any other library with template types having dependent
153  *  member types named `type`, like the standard trait types.
154  */
155 template <typename T>
156 using _t = typename T::type;
157
158 /**
159  * A type trait to remove all const volatile and reference qualifiers on a
160  * type T
161  */
162 template <typename T>
163 struct remove_cvref {
164   using type =
165       typename std::remove_cv<typename std::remove_reference<T>::type>::type;
166 };
167 template <typename T>
168 using remove_cvref_t = typename remove_cvref<T>::type;
169
170 /**
171  *  type_t
172  *
173  *  A type alias for the first template type argument. `type_t` is useful for
174  *  controlling class-template and function-template partial specialization.
175  *
176  *  Example:
177  *
178  *    template <typename Value>
179  *    class Container {
180  *     public:
181  *      template <typename... Args>
182  *      Container(
183  *          type_t<in_place_t, decltype(Value(std::declval<Args>()...))>,
184  *          Args&&...);
185  *    };
186  *
187  *  void_t
188  *
189  *  A type alias for `void`. `void_t` is useful for controling class-template
190  *  and function-template partial specialization.
191  *
192  *  Example:
193  *
194  *    // has_value_type<T>::value is true if T has a nested type `value_type`
195  *    template <class T, class = void>
196  *    struct has_value_type
197  *        : std::false_type {};
198  *
199  *    template <class T>
200  *    struct has_value_type<T, folly::void_t<typename T::value_type>>
201  *        : std::true_type {};
202  */
203
204 /**
205  * There is a bug in libstdc++, libc++, and MSVC's STL that causes it to
206  * ignore unused template parameter arguments in template aliases and does not
207  * cause substitution failures. This defect has been recorded here:
208  * http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#1558.
209  *
210  * This causes the implementation of std::void_t to be buggy, as it is likely
211  * defined as something like the following:
212  *
213  *  template <typename...>
214  *  using void_t = void;
215  *
216  * This causes the compiler to ignore all the template arguments and does not
217  * help when one wants to cause substitution failures.  Rather declarations
218  * which have void_t in orthogonal specializations are treated as the same.
219  * For example, assuming the possible `T` types are only allowed to have
220  * either the alias `one` or `two` and never both or none:
221  *
222  *  template <typename T,
223  *            typename std::void_t<std::decay_t<T>::one>* = nullptr>
224  *  void foo(T&&) {}
225  *  template <typename T,
226  *            typename std::void_t<std::decay_t<T>::two>* = nullptr>
227  *  void foo(T&&) {}
228  *
229  * The second foo() will be a redefinition because it conflicts with the first
230  * one; void_t does not cause substitution failures - the template types are
231  * just ignored.
232  */
233
234 namespace traits_detail {
235 template <class T, class...>
236 struct type_t_ {
237   using type = T;
238 };
239 } // namespace traits_detail
240
241 template <class T, class... Ts>
242 using type_t = typename traits_detail::type_t_<T, Ts...>::type;
243 template <class... Ts>
244 using void_t = type_t<void, Ts...>;
245
246 /**
247  * IsRelocatable<T>::value describes the ability of moving around
248  * memory a value of type T by using memcpy (as opposed to the
249  * conservative approach of calling the copy constructor and then
250  * destroying the old temporary. Essentially for a relocatable type,
251  * the following two sequences of code should be semantically
252  * equivalent:
253  *
254  * void move1(T * from, T * to) {
255  *   new(to) T(from);
256  *   (*from).~T();
257  * }
258  *
259  * void move2(T * from, T * to) {
260  *   memcpy(to, from, sizeof(T));
261  * }
262  *
263  * Most C++ types are relocatable; the ones that aren't would include
264  * internal pointers or (very rarely) would need to update remote
265  * pointers to pointers tracking them. All C++ primitive types and
266  * type constructors are relocatable.
267  *
268  * This property can be used in a variety of optimizations. Currently
269  * fbvector uses this property intensively.
270  *
271  * The default conservatively assumes the type is not
272  * relocatable. Several specializations are defined for known
273  * types. You may want to add your own specializations. Do so in
274  * namespace folly and make sure you keep the specialization of
275  * IsRelocatable<SomeStruct> in the same header as SomeStruct.
276  *
277  * You may also declare a type to be relocatable by including
278  *    `typedef std::true_type IsRelocatable;`
279  * in the class header.
280  *
281  * It may be unset in a base class by overriding the typedef to false_type.
282  */
283 /*
284  * IsTriviallyCopyable describes the value semantics property. C++11 contains
285  * the type trait is_trivially_copyable; however, it is not yet implemented
286  * in gcc (as of 4.7.1), and the user may wish to specify otherwise.
287  */
288 /*
289  * IsZeroInitializable describes the property that default construction is the
290  * same as memset(dst, 0, sizeof(T)).
291  */
292
293 namespace traits_detail {
294
295 #define FOLLY_HAS_TRUE_XXX(name)                                             \
296   FOLLY_CREATE_HAS_MEMBER_TYPE_TRAITS(has_##name, name);                     \
297   template <class T>                                                         \
298   struct name##_is_true : std::is_same<typename T::name, std::true_type> {}; \
299   template <class T>                                                         \
300   struct has_true_##name : std::conditional<                                 \
301                                has_##name<T>::value,                         \
302                                name##_is_true<T>,                            \
303                                std::false_type>::type {};
304
305 FOLLY_HAS_TRUE_XXX(IsRelocatable)
306 FOLLY_HAS_TRUE_XXX(IsZeroInitializable)
307 FOLLY_HAS_TRUE_XXX(IsTriviallyCopyable)
308
309 #undef FOLLY_HAS_TRUE_XXX
310
311 // Older versions of libstdc++ do not provide std::is_trivially_copyable
312 #if defined(__clang__) && !defined(_LIBCPP_VERSION)
313 template <class T>
314 struct is_trivially_copyable
315     : std::integral_constant<bool, __is_trivially_copyable(T)> {};
316 #elif defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5
317 template <class T>
318 struct is_trivially_copyable : std::is_trivial<T> {};
319 #else
320 template <class T>
321 using is_trivially_copyable = std::is_trivially_copyable<T>;
322 #endif
323 } // namespace traits_detail
324
325 struct Ignore {
326   Ignore() = default;
327   template <class T>
328   constexpr /* implicit */ Ignore(const T&) {}
329   template <class T>
330   const Ignore& operator=(T const&) const { return *this; }
331 };
332
333 template <class...>
334 using Ignored = Ignore;
335
336 namespace traits_detail_IsEqualityComparable {
337 Ignore operator==(Ignore, Ignore);
338
339 template <class T, class U = T>
340 struct IsEqualityComparable
341     : std::is_convertible<
342           decltype(std::declval<T>() == std::declval<U>()),
343           bool
344       > {};
345 } // namespace traits_detail_IsEqualityComparable
346
347 /* using override */ using traits_detail_IsEqualityComparable::
348     IsEqualityComparable;
349
350 namespace traits_detail_IsLessThanComparable {
351 Ignore operator<(Ignore, Ignore);
352
353 template <class T, class U = T>
354 struct IsLessThanComparable
355     : std::is_convertible<
356           decltype(std::declval<T>() < std::declval<U>()),
357           bool
358       > {};
359 } // namespace traits_detail_IsLessThanComparable
360
361 /* using override */ using traits_detail_IsLessThanComparable::
362     IsLessThanComparable;
363
364 namespace traits_detail_IsNothrowSwappable {
365 #if defined(__cpp_lib_is_swappable) || (_CPPLIB_VER && _HAS_CXX17)
366 // MSVC 2015+ already implements the C++17 P0185R1 proposal which
367 // adds std::is_nothrow_swappable, so use it instead if C++17 mode
368 // is enabled.
369 template <typename T>
370 using IsNothrowSwappable = std::is_nothrow_swappable<T>;
371 #elif _CPPLIB_VER
372 // MSVC 2015+ defines the base even if C++17 is disabled, and
373 // MSVC 2015 has issues with our fallback implementation due to
374 // over-eager evaluation of noexcept.
375 template <typename T>
376 using IsNothrowSwappable = std::_Is_nothrow_swappable<T>;
377 #else
378 /* using override */ using std::swap;
379
380 template <class T>
381 struct IsNothrowSwappable
382     : std::integral_constant<bool,
383         std::is_nothrow_move_constructible<T>::value &&
384         noexcept(swap(std::declval<T&>(), std::declval<T&>()))
385       > {};
386 #endif
387 } // namespace traits_detail_IsNothrowSwappable
388
389 /* using override */ using traits_detail_IsNothrowSwappable::IsNothrowSwappable;
390
391 template <class T> struct IsTriviallyCopyable
392   : std::conditional<
393       traits_detail::has_IsTriviallyCopyable<T>::value,
394       traits_detail::has_true_IsTriviallyCopyable<T>,
395       traits_detail::is_trivially_copyable<T>
396     >::type {};
397
398 template <class T> struct IsRelocatable
399   : std::conditional<
400       traits_detail::has_IsRelocatable<T>::value,
401       traits_detail::has_true_IsRelocatable<T>,
402       // TODO add this line (and some tests for it) when we upgrade to gcc 4.7
403       //std::is_trivially_move_constructible<T>::value ||
404       IsTriviallyCopyable<T>
405     >::type {};
406
407 template <class T> struct IsZeroInitializable
408   : std::conditional<
409       traits_detail::has_IsZeroInitializable<T>::value,
410       traits_detail::has_true_IsZeroInitializable<T>,
411       std::integral_constant<bool, !std::is_class<T>::value>
412     >::type {};
413
414 template <typename...>
415 struct Conjunction : std::true_type {};
416 template <typename T>
417 struct Conjunction<T> : T {};
418 template <typename T, typename... TList>
419 struct Conjunction<T, TList...>
420     : std::conditional<T::value, Conjunction<TList...>, T>::type {};
421
422 template <typename...>
423 struct Disjunction : std::false_type {};
424 template <typename T>
425 struct Disjunction<T> : T {};
426 template <typename T, typename... TList>
427 struct Disjunction<T, TList...>
428     : std::conditional<T::value, T, Disjunction<TList...>>::type {};
429
430 template <typename T>
431 struct Negation : std::integral_constant<bool, !T::value> {};
432
433 template <bool... Bs>
434 struct Bools {
435   using valid_type = bool;
436   static constexpr std::size_t size() {
437     return sizeof...(Bs);
438   }
439 };
440
441 // Lighter-weight than Conjunction, but evaluates all sub-conditions eagerly.
442 template <class... Ts>
443 struct StrictConjunction
444     : std::is_same<Bools<Ts::value...>, Bools<(Ts::value || true)...>> {};
445
446 template <class... Ts>
447 struct StrictDisjunction
448   : Negation<
449       std::is_same<Bools<Ts::value...>, Bools<(Ts::value && false)...>>
450     > {};
451
452 } // namespace folly
453
454 /**
455  * Use this macro ONLY inside namespace folly. When using it with a
456  * regular type, use it like this:
457  *
458  * // Make sure you're at namespace ::folly scope
459  * template <> FOLLY_ASSUME_RELOCATABLE(MyType)
460  *
461  * When using it with a template type, use it like this:
462  *
463  * // Make sure you're at namespace ::folly scope
464  * template <class T1, class T2>
465  * FOLLY_ASSUME_RELOCATABLE(MyType<T1, T2>)
466  */
467 #define FOLLY_ASSUME_RELOCATABLE(...) \
468   struct IsRelocatable<  __VA_ARGS__ > : std::true_type {};
469
470 /**
471  * The FOLLY_ASSUME_FBVECTOR_COMPATIBLE* macros below encode the
472  * assumption that the type is relocatable per IsRelocatable
473  * above. Many types can be assumed to satisfy this condition, but
474  * it is the responsibility of the user to state that assumption.
475  * User-defined classes will not be optimized for use with
476  * fbvector (see FBVector.h) unless they state that assumption.
477  *
478  * Use FOLLY_ASSUME_FBVECTOR_COMPATIBLE with regular types like this:
479  *
480  * FOLLY_ASSUME_FBVECTOR_COMPATIBLE(MyType)
481  *
482  * The versions FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1, _2, _3, and _4
483  * allow using the macro for describing templatized classes with 1, 2,
484  * 3, and 4 template parameters respectively. For template classes
485  * just use the macro with the appropriate number and pass the name of
486  * the template to it. Example:
487  *
488  * template <class T1, class T2> class MyType { ... };
489  * ...
490  * // Make sure you're at global scope
491  * FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(MyType)
492  */
493
494 // Use this macro ONLY at global level (no namespace)
495 #define FOLLY_ASSUME_FBVECTOR_COMPATIBLE(...) \
496   namespace folly {                           \
497   template <>                                 \
498   FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__)       \
499   }
500 // Use this macro ONLY at global level (no namespace)
501 #define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(...) \
502   namespace folly {                             \
503   template <class T1>                           \
504   FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__<T1>)     \
505   }
506 // Use this macro ONLY at global level (no namespace)
507 #define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(...) \
508   namespace folly {                             \
509   template <class T1, class T2>                 \
510   FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__<T1, T2>) \
511   }
512 // Use this macro ONLY at global level (no namespace)
513 #define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(...)     \
514   namespace folly {                                 \
515   template <class T1, class T2, class T3>           \
516   FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__<T1, T2, T3>) \
517   }
518 // Use this macro ONLY at global level (no namespace)
519 #define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_4(...)         \
520   namespace folly {                                     \
521   template <class T1, class T2, class T3, class T4>     \
522   FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__<T1, T2, T3, T4>) \
523   }
524
525 /**
526  * Instantiate FOLLY_ASSUME_FBVECTOR_COMPATIBLE for a few types. It is
527  * safe to assume that pair is compatible if both of its components
528  * are. Furthermore, all STL containers can be assumed to comply,
529  * although that is not guaranteed by the standard.
530  */
531
532 FOLLY_NAMESPACE_STD_BEGIN
533
534 template <class T, class U>
535   struct pair;
536 #ifndef _GLIBCXX_USE_FB
537 FOLLY_GLIBCXX_NAMESPACE_CXX11_BEGIN
538 template <class T, class R, class A>
539   class basic_string;
540 FOLLY_GLIBCXX_NAMESPACE_CXX11_END
541 #else
542 template <class T, class R, class A, class S>
543   class basic_string;
544 #endif
545 template <class T, class A>
546   class vector;
547 template <class T, class A>
548   class deque;
549 FOLLY_GLIBCXX_NAMESPACE_CXX11_BEGIN
550 template <class T, class A>
551   class list;
552 FOLLY_GLIBCXX_NAMESPACE_CXX11_END
553 template <class T, class C, class A>
554   class set;
555 template <class K, class V, class C, class A>
556   class map;
557 template <class T>
558   class shared_ptr;
559
560 FOLLY_NAMESPACE_STD_END
561
562 namespace folly {
563
564 // STL commonly-used types
565 template <class T, class U>
566 struct IsRelocatable< std::pair<T, U> >
567     : std::integral_constant<bool,
568         IsRelocatable<T>::value &&
569         IsRelocatable<U>::value> {};
570
571 // Is T one of T1, T2, ..., Tn?
572 template <typename T, typename... Ts>
573 using IsOneOf = StrictDisjunction<std::is_same<T, Ts>...>;
574
575 /*
576  * Complementary type traits for integral comparisons.
577  *
578  * For instance, `if(x < 0)` yields an error in clang for unsigned types
579  *  when -Werror is used due to -Wtautological-compare
580  *
581  *
582  * @author: Marcelo Juchem <marcelo@fb.com>
583  */
584
585 namespace detail {
586
587 template <typename T, bool>
588 struct is_negative_impl {
589   constexpr static bool check(T x) { return x < 0; }
590 };
591
592 template <typename T>
593 struct is_negative_impl<T, false> {
594   constexpr static bool check(T) { return false; }
595 };
596
597 // folly::to integral specializations can end up generating code
598 // inside what are really static ifs (not executed because of the templated
599 // types) that violate -Wsign-compare and/or -Wbool-compare so suppress them
600 // in order to not prevent all calling code from using it.
601 FOLLY_PUSH_WARNING
602 FOLLY_GCC_DISABLE_WARNING("-Wsign-compare")
603 #if __GNUC_PREREQ(5, 0)
604 FOLLY_GCC_DISABLE_WARNING("-Wbool-compare")
605 #endif
606 FOLLY_MSVC_DISABLE_WARNING(4388) // sign-compare
607 FOLLY_MSVC_DISABLE_WARNING(4804) // bool-compare
608
609 template <typename RHS, RHS rhs, typename LHS>
610 bool less_than_impl(LHS const lhs) {
611   return
612     rhs > std::numeric_limits<LHS>::max() ? true :
613     rhs <= std::numeric_limits<LHS>::min() ? false :
614     lhs < rhs;
615 }
616
617 template <typename RHS, RHS rhs, typename LHS>
618 bool greater_than_impl(LHS const lhs) {
619   return
620     rhs > std::numeric_limits<LHS>::max() ? false :
621     rhs < std::numeric_limits<LHS>::min() ? true :
622     lhs > rhs;
623 }
624
625 FOLLY_POP_WARNING
626
627 } // namespace detail
628
629 // same as `x < 0`
630 template <typename T>
631 constexpr bool is_negative(T x) {
632   return folly::detail::is_negative_impl<T, std::is_signed<T>::value>::check(x);
633 }
634
635 // same as `x <= 0`
636 template <typename T>
637 constexpr bool is_non_positive(T x) { return !x || folly::is_negative(x); }
638
639 // same as `x > 0`
640 template <typename T>
641 constexpr bool is_positive(T x) { return !is_non_positive(x); }
642
643 // same as `x >= 0`
644 template <typename T>
645 constexpr bool is_non_negative(T x) {
646   return !x || is_positive(x);
647 }
648
649 template <typename RHS, RHS rhs, typename LHS>
650 bool less_than(LHS const lhs) {
651   return detail::less_than_impl<
652     RHS, rhs, typename std::remove_reference<LHS>::type
653   >(lhs);
654 }
655
656 template <typename RHS, RHS rhs, typename LHS>
657 bool greater_than(LHS const lhs) {
658   return detail::greater_than_impl<
659     RHS, rhs, typename std::remove_reference<LHS>::type
660   >(lhs);
661 }
662 } // namespace folly
663
664 // Assume nothing when compiling with MSVC.
665 #ifndef _MSC_VER
666 // gcc-5.0 changed string's implementation in libstdc++ to be non-relocatable
667 #if !_GLIBCXX_USE_CXX11_ABI
668 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(std::basic_string)
669 #endif
670 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::vector)
671 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::list)
672 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::deque)
673 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::unique_ptr)
674 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(std::shared_ptr)
675 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(std::function)
676 #endif
677
678 /* Some combinations of compilers and C++ libraries make __int128 and
679  * unsigned __int128 available but do not correctly define their standard type
680  * traits.
681  *
682  * If FOLLY_SUPPLY_MISSING_INT128_TRAITS is defined, we define these traits
683  * here.
684  *
685  * @author: Phil Willoughby <philwill@fb.com>
686  */
687 #if FOLLY_SUPPLY_MISSING_INT128_TRAITS
688 FOLLY_NAMESPACE_STD_BEGIN
689 template <>
690 struct is_arithmetic<__int128> : ::std::true_type {};
691 template <>
692 struct is_arithmetic<unsigned __int128> : ::std::true_type {};
693 template <>
694 struct is_integral<__int128> : ::std::true_type {};
695 template <>
696 struct is_integral<unsigned __int128> : ::std::true_type {};
697 template <>
698 struct make_unsigned<__int128> {
699   typedef unsigned __int128 type;
700 };
701 template <>
702 struct make_signed<__int128> {
703   typedef __int128 type;
704 };
705 template <>
706 struct make_unsigned<unsigned __int128> {
707   typedef unsigned __int128 type;
708 };
709 template <>
710 struct make_signed<unsigned __int128> {
711   typedef __int128 type;
712 };
713 template <>
714 struct is_signed<__int128> : ::std::true_type {};
715 template <>
716 struct is_unsigned<unsigned __int128> : ::std::true_type {};
717 FOLLY_NAMESPACE_STD_END
718 #endif // FOLLY_SUPPLY_MISSING_INT128_TRAITS