Folly.Poly: a library for creating type-erasing polymorphic wrappers
[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  *  type_t
160  *
161  *  A type alias for the first template type argument. `type_t` is useful for
162  *  controlling class-template and function-template partial specialization.
163  *
164  *  Example:
165  *
166  *    template <typename Value>
167  *    class Container {
168  *     public:
169  *      template <typename... Args>
170  *      Container(
171  *          type_t<in_place_t, decltype(Value(std::declval<Args>()...))>,
172  *          Args&&...);
173  *    };
174  *
175  *  void_t
176  *
177  *  A type alias for `void`. `void_t` is useful for controling class-template
178  *  and function-template partial specialization.
179  *
180  *  Example:
181  *
182  *    // has_value_type<T>::value is true if T has a nested type `value_type`
183  *    template <class T, class = void>
184  *    struct has_value_type
185  *        : std::false_type {};
186  *
187  *    template <class T>
188  *    struct has_value_type<T, folly::void_t<typename T::value_type>>
189  *        : std::true_type {};
190  */
191
192 /**
193  * There is a bug in libstdc++, libc++, and MSVC's STL that causes it to
194  * ignore unused template parameter arguments in template aliases and does not
195  * cause substitution failures. This defect has been recorded here:
196  * http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#1558.
197  *
198  * This causes the implementation of std::void_t to be buggy, as it is likely
199  * defined as something like the following:
200  *
201  *  template <typename...>
202  *  using void_t = void;
203  *
204  * This causes the compiler to ignore all the template arguments and does not
205  * help when one wants to cause substitution failures.  Rather declarations
206  * which have void_t in orthogonal specializations are treated as the same.
207  * For example, assuming the possible `T` types are only allowed to have
208  * either the alias `one` or `two` and never both or none:
209  *
210  *  template <typename T,
211  *            typename std::void_t<std::decay_t<T>::one>* = nullptr>
212  *  void foo(T&&) {}
213  *  template <typename T,
214  *            typename std::void_t<std::decay_t<T>::two>* = nullptr>
215  *  void foo(T&&) {}
216  *
217  * The second foo() will be a redefinition because it conflicts with the first
218  * one; void_t does not cause substitution failures - the template types are
219  * just ignored.
220  */
221
222 namespace traits_detail {
223 template <class...>
224 struct type_t_ {
225   template <class T>
226   using apply = T;
227 };
228 } // namespace traits_detail
229
230 template <class T, class... Ts>
231 using type_t = typename traits_detail::type_t_<Ts...>::template apply<T>;
232 template <class... Ts>
233 using void_t = type_t<void, Ts...>;
234
235 /**
236  * IsRelocatable<T>::value describes the ability of moving around
237  * memory a value of type T by using memcpy (as opposed to the
238  * conservative approach of calling the copy constructor and then
239  * destroying the old temporary. Essentially for a relocatable type,
240  * the following two sequences of code should be semantically
241  * equivalent:
242  *
243  * void move1(T * from, T * to) {
244  *   new(to) T(from);
245  *   (*from).~T();
246  * }
247  *
248  * void move2(T * from, T * to) {
249  *   memcpy(to, from, sizeof(T));
250  * }
251  *
252  * Most C++ types are relocatable; the ones that aren't would include
253  * internal pointers or (very rarely) would need to update remote
254  * pointers to pointers tracking them. All C++ primitive types and
255  * type constructors are relocatable.
256  *
257  * This property can be used in a variety of optimizations. Currently
258  * fbvector uses this property intensively.
259  *
260  * The default conservatively assumes the type is not
261  * relocatable. Several specializations are defined for known
262  * types. You may want to add your own specializations. Do so in
263  * namespace folly and make sure you keep the specialization of
264  * IsRelocatable<SomeStruct> in the same header as SomeStruct.
265  *
266  * You may also declare a type to be relocatable by including
267  *    `typedef std::true_type IsRelocatable;`
268  * in the class header.
269  *
270  * It may be unset in a base class by overriding the typedef to false_type.
271  */
272 /*
273  * IsTriviallyCopyable describes the value semantics property. C++11 contains
274  * the type trait is_trivially_copyable; however, it is not yet implemented
275  * in gcc (as of 4.7.1), and the user may wish to specify otherwise.
276  */
277 /*
278  * IsZeroInitializable describes the property that default construction is the
279  * same as memset(dst, 0, sizeof(T)).
280  */
281
282 namespace traits_detail {
283
284 #define FOLLY_HAS_TRUE_XXX(name)                                             \
285   FOLLY_CREATE_HAS_MEMBER_TYPE_TRAITS(has_##name, name);                     \
286   template <class T>                                                         \
287   struct name##_is_true : std::is_same<typename T::name, std::true_type> {}; \
288   template <class T>                                                         \
289   struct has_true_##name : std::conditional<                                 \
290                                has_##name<T>::value,                         \
291                                name##_is_true<T>,                            \
292                                std::false_type>::type {};
293
294 FOLLY_HAS_TRUE_XXX(IsRelocatable)
295 FOLLY_HAS_TRUE_XXX(IsZeroInitializable)
296 FOLLY_HAS_TRUE_XXX(IsTriviallyCopyable)
297
298 #undef FOLLY_HAS_TRUE_XXX
299
300 // Older versions of libstdc++ do not provide std::is_trivially_copyable
301 #if defined(__clang__) && !defined(_LIBCPP_VERSION)
302 template <class T>
303 struct is_trivially_copyable
304     : std::integral_constant<bool, __is_trivially_copyable(T)> {};
305 #elif defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5
306 template <class T>
307 struct is_trivially_copyable : std::is_trivial<T> {};
308 #else
309 template <class T>
310 using is_trivially_copyable = std::is_trivially_copyable<T>;
311 #endif
312 } // namespace traits_detail
313
314 struct Ignore {
315   Ignore() = default;
316   template <class T>
317   constexpr /* implicit */ Ignore(const T&) {}
318   template <class T>
319   const Ignore& operator=(T const&) const { return *this; }
320 };
321
322 template <class...>
323 using Ignored = Ignore;
324
325 namespace traits_detail_IsEqualityComparable {
326 Ignore operator==(Ignore, Ignore);
327
328 template <class T, class U = T>
329 struct IsEqualityComparable
330     : std::is_convertible<
331           decltype(std::declval<T>() == std::declval<U>()),
332           bool
333       > {};
334 } // namespace traits_detail_IsEqualityComparable
335
336 /* using override */ using traits_detail_IsEqualityComparable::
337     IsEqualityComparable;
338
339 namespace traits_detail_IsLessThanComparable {
340 Ignore operator<(Ignore, Ignore);
341
342 template <class T, class U = T>
343 struct IsLessThanComparable
344     : std::is_convertible<
345           decltype(std::declval<T>() < std::declval<U>()),
346           bool
347       > {};
348 } // namespace traits_detail_IsLessThanComparable
349
350 /* using override */ using traits_detail_IsLessThanComparable::
351     IsLessThanComparable;
352
353 namespace traits_detail_IsNothrowSwappable {
354 #if defined(__cpp_lib_is_swappable) || (_CPPLIB_VER && _HAS_CXX17)
355 // MSVC 2015+ already implements the C++17 P0185R1 proposal which
356 // adds std::is_nothrow_swappable, so use it instead if C++17 mode
357 // is enabled.
358 template <typename T>
359 using IsNothrowSwappable = std::is_nothrow_swappable<T>;
360 #elif _CPPLIB_VER
361 // MSVC 2015+ defines the base even if C++17 is disabled, and
362 // MSVC 2015 has issues with our fallback implementation due to
363 // over-eager evaluation of noexcept.
364 template <typename T>
365 using IsNothrowSwappable = std::_Is_nothrow_swappable<T>;
366 #else
367 /* using override */ using std::swap;
368
369 template <class T>
370 struct IsNothrowSwappable
371     : std::integral_constant<bool,
372         std::is_nothrow_move_constructible<T>::value &&
373         noexcept(swap(std::declval<T&>(), std::declval<T&>()))
374       > {};
375 #endif
376 } // namespace traits_detail_IsNothrowSwappable
377
378 /* using override */ using traits_detail_IsNothrowSwappable::IsNothrowSwappable;
379
380 template <class T> struct IsTriviallyCopyable
381   : std::conditional<
382       traits_detail::has_IsTriviallyCopyable<T>::value,
383       traits_detail::has_true_IsTriviallyCopyable<T>,
384       traits_detail::is_trivially_copyable<T>
385     >::type {};
386
387 template <class T> struct IsRelocatable
388   : std::conditional<
389       traits_detail::has_IsRelocatable<T>::value,
390       traits_detail::has_true_IsRelocatable<T>,
391       // TODO add this line (and some tests for it) when we upgrade to gcc 4.7
392       //std::is_trivially_move_constructible<T>::value ||
393       IsTriviallyCopyable<T>
394     >::type {};
395
396 template <class T> struct IsZeroInitializable
397   : std::conditional<
398       traits_detail::has_IsZeroInitializable<T>::value,
399       traits_detail::has_true_IsZeroInitializable<T>,
400       std::integral_constant<bool, !std::is_class<T>::value>
401     >::type {};
402
403 template <typename...>
404 struct Conjunction : std::true_type {};
405 template <typename T>
406 struct Conjunction<T> : T {};
407 template <typename T, typename... TList>
408 struct Conjunction<T, TList...>
409     : std::conditional<T::value, Conjunction<TList...>, T>::type {};
410
411 template <typename...>
412 struct Disjunction : std::false_type {};
413 template <typename T>
414 struct Disjunction<T> : T {};
415 template <typename T, typename... TList>
416 struct Disjunction<T, TList...>
417     : std::conditional<T::value, T, Disjunction<TList...>>::type {};
418
419 template <typename T>
420 struct Negation : std::integral_constant<bool, !T::value> {};
421
422 template <bool... Bs>
423 struct Bools {
424   using valid_type = bool;
425   static constexpr std::size_t size() {
426     return sizeof...(Bs);
427   }
428 };
429
430 // Lighter-weight than Conjunction, but evaluates all sub-conditions eagerly.
431 template <class... Ts>
432 struct StrictConjunction
433     : std::is_same<Bools<Ts::value...>, Bools<(Ts::value || true)...>> {};
434
435 template <class... Ts>
436 struct StrictDisjunction
437   : Negation<
438       std::is_same<Bools<Ts::value...>, Bools<(Ts::value && false)...>>
439     > {};
440
441 } // namespace folly
442
443 /**
444  * Use this macro ONLY inside namespace folly. When using it with a
445  * regular type, use it like this:
446  *
447  * // Make sure you're at namespace ::folly scope
448  * template <> FOLLY_ASSUME_RELOCATABLE(MyType)
449  *
450  * When using it with a template type, use it like this:
451  *
452  * // Make sure you're at namespace ::folly scope
453  * template <class T1, class T2>
454  * FOLLY_ASSUME_RELOCATABLE(MyType<T1, T2>)
455  */
456 #define FOLLY_ASSUME_RELOCATABLE(...) \
457   struct IsRelocatable<  __VA_ARGS__ > : std::true_type {};
458
459 /**
460  * The FOLLY_ASSUME_FBVECTOR_COMPATIBLE* macros below encode the
461  * assumption that the type is relocatable per IsRelocatable
462  * above. Many types can be assumed to satisfy this condition, but
463  * it is the responsibility of the user to state that assumption.
464  * User-defined classes will not be optimized for use with
465  * fbvector (see FBVector.h) unless they state that assumption.
466  *
467  * Use FOLLY_ASSUME_FBVECTOR_COMPATIBLE with regular types like this:
468  *
469  * FOLLY_ASSUME_FBVECTOR_COMPATIBLE(MyType)
470  *
471  * The versions FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1, _2, _3, and _4
472  * allow using the macro for describing templatized classes with 1, 2,
473  * 3, and 4 template parameters respectively. For template classes
474  * just use the macro with the appropriate number and pass the name of
475  * the template to it. Example:
476  *
477  * template <class T1, class T2> class MyType { ... };
478  * ...
479  * // Make sure you're at global scope
480  * FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(MyType)
481  */
482
483 // Use this macro ONLY at global level (no namespace)
484 #define FOLLY_ASSUME_FBVECTOR_COMPATIBLE(...) \
485   namespace folly {                           \
486   template <>                                 \
487   FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__)       \
488   }
489 // Use this macro ONLY at global level (no namespace)
490 #define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(...) \
491   namespace folly {                             \
492   template <class T1>                           \
493   FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__<T1>)     \
494   }
495 // Use this macro ONLY at global level (no namespace)
496 #define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(...) \
497   namespace folly {                             \
498   template <class T1, class T2>                 \
499   FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__<T1, T2>) \
500   }
501 // Use this macro ONLY at global level (no namespace)
502 #define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(...)     \
503   namespace folly {                                 \
504   template <class T1, class T2, class T3>           \
505   FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__<T1, T2, T3>) \
506   }
507 // Use this macro ONLY at global level (no namespace)
508 #define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_4(...)         \
509   namespace folly {                                     \
510   template <class T1, class T2, class T3, class T4>     \
511   FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__<T1, T2, T3, T4>) \
512   }
513
514 /**
515  * Instantiate FOLLY_ASSUME_FBVECTOR_COMPATIBLE for a few types. It is
516  * safe to assume that pair is compatible if both of its components
517  * are. Furthermore, all STL containers can be assumed to comply,
518  * although that is not guaranteed by the standard.
519  */
520
521 FOLLY_NAMESPACE_STD_BEGIN
522
523 template <class T, class U>
524   struct pair;
525 #ifndef _GLIBCXX_USE_FB
526 FOLLY_GLIBCXX_NAMESPACE_CXX11_BEGIN
527 template <class T, class R, class A>
528   class basic_string;
529 FOLLY_GLIBCXX_NAMESPACE_CXX11_END
530 #else
531 template <class T, class R, class A, class S>
532   class basic_string;
533 #endif
534 template <class T, class A>
535   class vector;
536 template <class T, class A>
537   class deque;
538 FOLLY_GLIBCXX_NAMESPACE_CXX11_BEGIN
539 template <class T, class A>
540   class list;
541 FOLLY_GLIBCXX_NAMESPACE_CXX11_END
542 template <class T, class C, class A>
543   class set;
544 template <class K, class V, class C, class A>
545   class map;
546 template <class T>
547   class shared_ptr;
548
549 FOLLY_NAMESPACE_STD_END
550
551 namespace folly {
552
553 // STL commonly-used types
554 template <class T, class U>
555 struct IsRelocatable< std::pair<T, U> >
556     : std::integral_constant<bool,
557         IsRelocatable<T>::value &&
558         IsRelocatable<U>::value> {};
559
560 // Is T one of T1, T2, ..., Tn?
561 template <typename T, typename... Ts>
562 using IsOneOf = StrictDisjunction<std::is_same<T, Ts>...>;
563
564 /*
565  * Complementary type traits for integral comparisons.
566  *
567  * For instance, `if(x < 0)` yields an error in clang for unsigned types
568  *  when -Werror is used due to -Wtautological-compare
569  *
570  *
571  * @author: Marcelo Juchem <marcelo@fb.com>
572  */
573
574 namespace detail {
575
576 template <typename T, bool>
577 struct is_negative_impl {
578   constexpr static bool check(T x) { return x < 0; }
579 };
580
581 template <typename T>
582 struct is_negative_impl<T, false> {
583   constexpr static bool check(T) { return false; }
584 };
585
586 // folly::to integral specializations can end up generating code
587 // inside what are really static ifs (not executed because of the templated
588 // types) that violate -Wsign-compare and/or -Wbool-compare so suppress them
589 // in order to not prevent all calling code from using it.
590 FOLLY_PUSH_WARNING
591 FOLLY_GCC_DISABLE_WARNING("-Wsign-compare")
592 #if __GNUC_PREREQ(5, 0)
593 FOLLY_GCC_DISABLE_WARNING("-Wbool-compare")
594 #endif
595 FOLLY_MSVC_DISABLE_WARNING(4388) // sign-compare
596 FOLLY_MSVC_DISABLE_WARNING(4804) // bool-compare
597
598 template <typename RHS, RHS rhs, typename LHS>
599 bool less_than_impl(LHS const lhs) {
600   return
601     rhs > std::numeric_limits<LHS>::max() ? true :
602     rhs <= std::numeric_limits<LHS>::min() ? false :
603     lhs < rhs;
604 }
605
606 template <typename RHS, RHS rhs, typename LHS>
607 bool greater_than_impl(LHS const lhs) {
608   return
609     rhs > std::numeric_limits<LHS>::max() ? false :
610     rhs < std::numeric_limits<LHS>::min() ? true :
611     lhs > rhs;
612 }
613
614 FOLLY_POP_WARNING
615
616 } // namespace detail
617
618 // same as `x < 0`
619 template <typename T>
620 constexpr bool is_negative(T x) {
621   return folly::detail::is_negative_impl<T, std::is_signed<T>::value>::check(x);
622 }
623
624 // same as `x <= 0`
625 template <typename T>
626 constexpr bool is_non_positive(T x) { return !x || folly::is_negative(x); }
627
628 // same as `x > 0`
629 template <typename T>
630 constexpr bool is_positive(T x) { return !is_non_positive(x); }
631
632 // same as `x >= 0`
633 template <typename T>
634 constexpr bool is_non_negative(T x) {
635   return !x || is_positive(x);
636 }
637
638 template <typename RHS, RHS rhs, typename LHS>
639 bool less_than(LHS const lhs) {
640   return detail::less_than_impl<
641     RHS, rhs, typename std::remove_reference<LHS>::type
642   >(lhs);
643 }
644
645 template <typename RHS, RHS rhs, typename LHS>
646 bool greater_than(LHS const lhs) {
647   return detail::greater_than_impl<
648     RHS, rhs, typename std::remove_reference<LHS>::type
649   >(lhs);
650 }
651 } // namespace folly
652
653 // Assume nothing when compiling with MSVC.
654 #ifndef _MSC_VER
655 // gcc-5.0 changed string's implementation in libstdc++ to be non-relocatable
656 #if !_GLIBCXX_USE_CXX11_ABI
657 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(std::basic_string)
658 #endif
659 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::vector)
660 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::list)
661 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::deque)
662 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::unique_ptr)
663 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(std::shared_ptr)
664 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(std::function)
665 #endif
666
667 /* Some combinations of compilers and C++ libraries make __int128 and
668  * unsigned __int128 available but do not correctly define their standard type
669  * traits.
670  *
671  * If FOLLY_SUPPLY_MISSING_INT128_TRAITS is defined, we define these traits
672  * here.
673  *
674  * @author: Phil Willoughby <philwill@fb.com>
675  */
676 #if FOLLY_SUPPLY_MISSING_INT128_TRAITS
677 FOLLY_NAMESPACE_STD_BEGIN
678 template <>
679 struct is_arithmetic<__int128> : ::std::true_type {};
680 template <>
681 struct is_arithmetic<unsigned __int128> : ::std::true_type {};
682 template <>
683 struct is_integral<__int128> : ::std::true_type {};
684 template <>
685 struct is_integral<unsigned __int128> : ::std::true_type {};
686 template <>
687 struct make_unsigned<__int128> {
688   typedef unsigned __int128 type;
689 };
690 template <>
691 struct make_signed<__int128> {
692   typedef __int128 type;
693 };
694 template <>
695 struct make_unsigned<unsigned __int128> {
696   typedef unsigned __int128 type;
697 };
698 template <>
699 struct make_signed<unsigned __int128> {
700   typedef __int128 type;
701 };
702 template <>
703 struct is_signed<__int128> : ::std::true_type {};
704 template <>
705 struct is_unsigned<unsigned __int128> : ::std::true_type {};
706 FOLLY_NAMESPACE_STD_END
707 #endif // FOLLY_SUPPLY_MISSING_INT128_TRAITS