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