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