Fix extension length counter in client hello parsing.
[folly.git] / folly / Traits.h
1 /*
2  * Copyright 2016 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 <memory>
22 #include <limits>
23 #include <type_traits>
24 #include <functional>
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 #include <boost/type_traits.hpp>
40 #include <boost/mpl/has_xxx.hpp>
41
42 namespace folly {
43
44 /**
45  * IsRelocatable<T>::value describes the ability of moving around
46  * memory a value of type T by using memcpy (as opposed to the
47  * conservative approach of calling the copy constructor and then
48  * destroying the old temporary. Essentially for a relocatable type,
49  * the following two sequences of code should be semantically
50  * equivalent:
51  *
52  * void move1(T * from, T * to) {
53  *   new(to) T(from);
54  *   (*from).~T();
55  * }
56  *
57  * void move2(T * from, T * to) {
58  *   memcpy(to, from, sizeof(T));
59  * }
60  *
61  * Most C++ types are relocatable; the ones that aren't would include
62  * internal pointers or (very rarely) would need to update remote
63  * pointers to pointers tracking them. All C++ primitive types and
64  * type constructors are relocatable.
65  *
66  * This property can be used in a variety of optimizations. Currently
67  * fbvector uses this property intensively.
68  *
69  * The default conservatively assumes the type is not
70  * relocatable. Several specializations are defined for known
71  * types. You may want to add your own specializations. Do so in
72  * namespace folly and make sure you keep the specialization of
73  * IsRelocatable<SomeStruct> in the same header as SomeStruct.
74  *
75  * You may also declare a type to be relocatable by including
76  *    `typedef std::true_type IsRelocatable;`
77  * in the class header.
78  *
79  * It may be unset in a base class by overriding the typedef to false_type.
80  */
81 /*
82  * IsTriviallyCopyable describes the value semantics property. C++11 contains
83  * the type trait is_trivially_copyable; however, it is not yet implemented
84  * in gcc (as of 4.7.1), and the user may wish to specify otherwise.
85  */
86 /*
87  * IsZeroInitializable describes the property that default construction is the
88  * same as memset(dst, 0, sizeof(T)).
89  */
90
91 namespace traits_detail {
92
93 #define FOLLY_HAS_TRUE_XXX(name)                                             \
94   BOOST_MPL_HAS_XXX_TRAIT_DEF(name)                                          \
95   template <class T>                                                         \
96   struct name##_is_true : std::is_same<typename T::name, std::true_type> {}; \
97   template <class T>                                                         \
98   struct has_true_##name : std::conditional<                                 \
99                                has_##name<T>::value,                         \
100                                name##_is_true<T>,                            \
101                                std::false_type>::type {};
102
103 FOLLY_HAS_TRUE_XXX(IsRelocatable)
104 FOLLY_HAS_TRUE_XXX(IsZeroInitializable)
105 FOLLY_HAS_TRUE_XXX(IsTriviallyCopyable)
106
107 #undef FOLLY_HAS_TRUE_XXX
108
109 // Older versions of libstdc++ do not provide std::is_trivially_copyable
110 #if defined(__clang__) && !defined(_LIBCPP_VERSION)
111 template <class T>
112 struct is_trivially_copyable
113     : std::integral_constant<bool, __is_trivially_copyable(T)> {};
114 #elif defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5
115 template <class T>
116 struct is_trivially_copyable : std::is_trivial<T> {};
117 #else
118 template <class T>
119 using is_trivially_copyable = std::is_trivially_copyable<T>;
120 #endif
121 }
122
123 struct Ignore {
124   template <class T>
125   /* implicit */ Ignore(const T&) {}
126   template <class T>
127   const Ignore& operator=(T const&) const { return *this; }
128 };
129
130 template <class...>
131 using Ignored = Ignore;
132
133 namespace traits_detail_IsEqualityComparable {
134 Ignore operator==(Ignore, Ignore);
135
136 template <class T, class U = T>
137 struct IsEqualityComparable
138     : std::is_convertible<
139           decltype(std::declval<T>() == std::declval<U>()),
140           bool
141       > {};
142 }
143
144 /* using override */ using traits_detail_IsEqualityComparable::
145     IsEqualityComparable;
146
147 namespace traits_detail_IsLessThanComparable {
148 Ignore operator<(Ignore, Ignore);
149
150 template <class T, class U = T>
151 struct IsLessThanComparable
152     : std::is_convertible<
153           decltype(std::declval<T>() < std::declval<U>()),
154           bool
155       > {};
156 }
157
158 /* using override */ using traits_detail_IsLessThanComparable::
159     IsLessThanComparable;
160
161 namespace traits_detail_IsNothrowSwappable {
162 /* using override */ using std::swap;
163
164 template <class T>
165 struct IsNothrowSwappable
166     : std::integral_constant<bool,
167         std::is_nothrow_move_constructible<T>::value &&
168         noexcept(swap(std::declval<T&>(), std::declval<T&>()))
169       > {};
170 }
171
172 /* using override */ using traits_detail_IsNothrowSwappable::IsNothrowSwappable;
173
174 template <class T> struct IsTriviallyCopyable
175   : std::conditional<
176       traits_detail::has_IsTriviallyCopyable<T>::value,
177       traits_detail::has_true_IsTriviallyCopyable<T>,
178       traits_detail::is_trivially_copyable<T>
179     >::type {};
180
181 template <class T> struct IsRelocatable
182   : std::conditional<
183       traits_detail::has_IsRelocatable<T>::value,
184       traits_detail::has_true_IsRelocatable<T>,
185       // TODO add this line (and some tests for it) when we upgrade to gcc 4.7
186       //std::is_trivially_move_constructible<T>::value ||
187       IsTriviallyCopyable<T>
188     >::type {};
189
190 template <class T> struct IsZeroInitializable
191   : std::conditional<
192       traits_detail::has_IsZeroInitializable<T>::value,
193       traits_detail::has_true_IsZeroInitializable<T>,
194       std::integral_constant<bool, !std::is_class<T>::value>
195     >::type {};
196
197 template <typename...>
198 struct Conjunction : std::true_type {};
199 template <typename T>
200 struct Conjunction<T> : T {};
201 template <typename T, typename... TList>
202 struct Conjunction<T, TList...>
203     : std::conditional<T::value, Conjunction<TList...>, T>::type {};
204
205 template <typename...>
206 struct Disjunction : std::false_type {};
207 template <typename T>
208 struct Disjunction<T> : T {};
209 template <typename T, typename... TList>
210 struct Disjunction<T, TList...>
211     : std::conditional<T::value, T, Disjunction<TList...>>::type {};
212
213 template <typename T>
214 struct Negation : std::integral_constant<bool, !T::value> {};
215
216 template <bool... Bs>
217 struct Bools {
218   using valid_type = bool;
219   static constexpr std::size_t size() {
220     return sizeof...(Bs);
221   }
222 };
223
224 // Lighter-weight than Conjunction, but evaluates all sub-conditions eagerly.
225 template <class... Ts>
226 using StrictConjunction =
227     std::is_same<Bools<Ts::value..., true>, Bools<true, Ts::value...>>;
228
229 } // namespace folly
230
231 /**
232  * Use this macro ONLY inside namespace folly. When using it with a
233  * regular type, use it like this:
234  *
235  * // Make sure you're at namespace ::folly scope
236  * template<> FOLLY_ASSUME_RELOCATABLE(MyType)
237  *
238  * When using it with a template type, use it like this:
239  *
240  * // Make sure you're at namespace ::folly scope
241  * template<class T1, class T2>
242  * FOLLY_ASSUME_RELOCATABLE(MyType<T1, T2>)
243  */
244 #define FOLLY_ASSUME_RELOCATABLE(...) \
245   struct IsRelocatable<  __VA_ARGS__ > : std::true_type {};
246
247 /**
248  * Use this macro ONLY inside namespace boost. When using it with a
249  * regular type, use it like this:
250  *
251  * // Make sure you're at namespace ::boost scope
252  * template<> FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(MyType)
253  *
254  * When using it with a template type, use it like this:
255  *
256  * // Make sure you're at namespace ::boost scope
257  * template<class T1, class T2>
258  * FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(MyType<T1, T2>)
259  */
260 #define FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(...) \
261   struct has_nothrow_constructor<  __VA_ARGS__ > : ::boost::true_type {};
262
263 /**
264  * The FOLLY_ASSUME_FBVECTOR_COMPATIBLE* macros below encode two
265  * assumptions: first, that the type is relocatable per IsRelocatable
266  * above, and that it has a nothrow constructor. Most types can be
267  * assumed to satisfy both conditions, but it is the responsibility of
268  * the user to state that assumption. User-defined classes will not
269  * work with fbvector (see FBVector.h) unless they state this
270  * combination of properties.
271  *
272  * Use FOLLY_ASSUME_FBVECTOR_COMPATIBLE with regular types like this:
273  *
274  * FOLLY_ASSUME_FBVECTOR_COMPATIBLE(MyType)
275  *
276  * The versions FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1, _2, _3, and _4
277  * allow using the macro for describing templatized classes with 1, 2,
278  * 3, and 4 template parameters respectively. For template classes
279  * just use the macro with the appropriate number and pass the name of
280  * the template to it. Example:
281  *
282  * template <class T1, class T2> class MyType { ... };
283  * ...
284  * // Make sure you're at global scope
285  * FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(MyType)
286  */
287
288 // Use this macro ONLY at global level (no namespace)
289 #define FOLLY_ASSUME_FBVECTOR_COMPATIBLE(...)                           \
290   namespace folly { template<> FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__) }   \
291   namespace boost { \
292   template<> FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(__VA_ARGS__) }
293 // Use this macro ONLY at global level (no namespace)
294 #define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(...)                         \
295   namespace folly {                                                     \
296   template <class T1> FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__<T1>) }       \
297     namespace boost {                                                   \
298     template <class T1> FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(__VA_ARGS__<T1>) }
299 // Use this macro ONLY at global level (no namespace)
300 #define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(...)                 \
301   namespace folly {                                             \
302   template <class T1, class T2>                                 \
303   FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__<T1, T2>) }               \
304     namespace boost {                                           \
305     template <class T1, class T2>                               \
306     FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(__VA_ARGS__<T1, T2>) }
307 // Use this macro ONLY at global level (no namespace)
308 #define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(...)                         \
309   namespace folly {                                                     \
310   template <class T1, class T2, class T3>                               \
311   FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__<T1, T2, T3>) }                   \
312     namespace boost {                                                   \
313     template <class T1, class T2, class T3>                             \
314     FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(__VA_ARGS__<T1, T2, T3>) }
315 // Use this macro ONLY at global level (no namespace)
316 #define FOLLY_ASSUME_FBVECTOR_COMPATIBLE_4(...)                         \
317   namespace folly {                                                     \
318   template <class T1, class T2, class T3, class T4>                     \
319   FOLLY_ASSUME_RELOCATABLE(__VA_ARGS__<T1, T2, T3, T4>) }               \
320     namespace boost {                                                   \
321     template <class T1, class T2, class T3, class T4>                   \
322     FOLLY_ASSUME_HAS_NOTHROW_CONSTRUCTOR(__VA_ARGS__<T1, T2, T3, T4>) }
323
324 /**
325  * Instantiate FOLLY_ASSUME_FBVECTOR_COMPATIBLE for a few types. It is
326  * safe to assume that pair is compatible if both of its components
327  * are. Furthermore, all STL containers can be assumed to comply,
328  * although that is not guaranteed by the standard.
329  */
330
331 FOLLY_NAMESPACE_STD_BEGIN
332
333 template <class T, class U>
334   struct pair;
335 #ifndef _GLIBCXX_USE_FB
336 FOLLY_GLIBCXX_NAMESPACE_CXX11_BEGIN
337 template <class T, class R, class A>
338   class basic_string;
339 FOLLY_GLIBCXX_NAMESPACE_CXX11_END
340 #else
341 template <class T, class R, class A, class S>
342   class basic_string;
343 #endif
344 template <class T, class A>
345   class vector;
346 template <class T, class A>
347   class deque;
348 FOLLY_GLIBCXX_NAMESPACE_CXX11_BEGIN
349 template <class T, class A>
350   class list;
351 FOLLY_GLIBCXX_NAMESPACE_CXX11_END
352 template <class T, class C, class A>
353   class set;
354 template <class K, class V, class C, class A>
355   class map;
356 template <class T>
357   class shared_ptr;
358
359 FOLLY_NAMESPACE_STD_END
360
361 namespace boost {
362
363 template <class T> class shared_ptr;
364
365 template <class T, class U>
366 struct has_nothrow_constructor< std::pair<T, U> >
367     : std::integral_constant<bool,
368         has_nothrow_constructor<T>::value &&
369         has_nothrow_constructor<U>::value> {};
370
371 } // namespace boost
372
373 namespace folly {
374
375 // STL commonly-used types
376 template <class T, class U>
377 struct IsRelocatable< std::pair<T, U> >
378     : std::integral_constant<bool,
379         IsRelocatable<T>::value &&
380         IsRelocatable<U>::value> {};
381
382 // Is T one of T1, T2, ..., Tn?
383 template <class T, class... Ts>
384 struct IsOneOf {
385   enum { value = false };
386 };
387
388 template <class T, class T1, class... Ts>
389 struct IsOneOf<T, T1, Ts...> {
390   enum { value = std::is_same<T, T1>::value || IsOneOf<T, Ts...>::value };
391 };
392
393 /*
394  * Complementary type traits for integral comparisons.
395  *
396  * For instance, `if(x < 0)` yields an error in clang for unsigned types
397  *  when -Werror is used due to -Wtautological-compare
398  *
399  *
400  * @author: Marcelo Juchem <marcelo@fb.com>
401  */
402
403 namespace detail {
404
405 template <typename T, bool>
406 struct is_negative_impl {
407   constexpr static bool check(T x) { return x < 0; }
408 };
409
410 template <typename T>
411 struct is_negative_impl<T, false> {
412   constexpr static bool check(T) { return false; }
413 };
414
415 // folly::to integral specializations can end up generating code
416 // inside what are really static ifs (not executed because of the templated
417 // types) that violate -Wsign-compare and/or -Wbool-compare so suppress them
418 // in order to not prevent all calling code from using it.
419 #pragma GCC diagnostic push
420 #pragma GCC diagnostic ignored "-Wsign-compare"
421 #if __GNUC_PREREQ(5, 0)
422 #pragma GCC diagnostic ignored "-Wbool-compare"
423 #endif
424
425 template <typename RHS, RHS rhs, typename LHS>
426 bool less_than_impl(LHS const lhs) {
427   return
428     rhs > std::numeric_limits<LHS>::max() ? true :
429     rhs <= std::numeric_limits<LHS>::min() ? false :
430     lhs < rhs;
431 }
432
433 template <typename RHS, RHS rhs, typename LHS>
434 bool greater_than_impl(LHS const lhs) {
435   return
436     rhs > std::numeric_limits<LHS>::max() ? false :
437     rhs < std::numeric_limits<LHS>::min() ? true :
438     lhs > rhs;
439 }
440
441 #pragma GCC diagnostic pop
442
443 } // namespace detail {
444
445 // same as `x < 0`
446 template <typename T>
447 constexpr bool is_negative(T x) {
448   return folly::detail::is_negative_impl<T, std::is_signed<T>::value>::check(x);
449 }
450
451 // same as `x <= 0`
452 template <typename T>
453 constexpr bool is_non_positive(T x) { return !x || folly::is_negative(x); }
454
455 // same as `x > 0`
456 template <typename T>
457 constexpr bool is_positive(T x) { return !is_non_positive(x); }
458
459 // same as `x >= 0`
460 template <typename T>
461 constexpr bool is_non_negative(T x) {
462   return !x || is_positive(x);
463 }
464
465 template <typename RHS, RHS rhs, typename LHS>
466 bool less_than(LHS const lhs) {
467   return detail::less_than_impl<
468     RHS, rhs, typename std::remove_reference<LHS>::type
469   >(lhs);
470 }
471
472 template <typename RHS, RHS rhs, typename LHS>
473 bool greater_than(LHS const lhs) {
474   return detail::greater_than_impl<
475     RHS, rhs, typename std::remove_reference<LHS>::type
476   >(lhs);
477 }
478
479 namespace traits_detail {
480 struct InPlaceTag {};
481 template <class>
482 struct InPlaceTypeTag {};
483 template <std::size_t>
484 struct InPlaceIndexTag {};
485 }
486
487 /**
488  * Like std::piecewise_construct, a tag type & instance used for in-place
489  * construction of non-movable contained types, e.g. by Synchronized.
490  * Follows the naming and design of std::in_place suggested in
491  * http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0032r2.pdf
492  */
493 using in_place_t = traits_detail::InPlaceTag (&)(traits_detail::InPlaceTag);
494
495 template <class T>
496 using in_place_type_t =
497     traits_detail::InPlaceTypeTag<T> (&)(traits_detail::InPlaceTypeTag<T>);
498
499 template <std::size_t I>
500 using in_place_index_t =
501     traits_detail::InPlaceIndexTag<I> (&)(traits_detail::InPlaceIndexTag<I>);
502
503 inline traits_detail::InPlaceTag in_place(traits_detail::InPlaceTag = {}) {
504   return {};
505 }
506
507 template <class T>
508 inline traits_detail::InPlaceTypeTag<T> in_place(
509     traits_detail::InPlaceTypeTag<T> = {}) {
510   return {};
511 }
512
513 template <std::size_t I>
514 inline traits_detail::InPlaceIndexTag<I> in_place(
515     traits_detail::InPlaceIndexTag<I> = {}) {
516   return {};
517 }
518
519 // For backwards compatibility:
520 using construct_in_place_t = in_place_t;
521
522 inline traits_detail::InPlaceTag construct_in_place(
523     traits_detail::InPlaceTag = {}) {
524   return {};
525 }
526
527 /**
528  * Initializer lists are a powerful compile time syntax introduced in C++11
529  * but due to their often conflicting syntax they are not used by APIs for
530  * construction.
531  *
532  * Further standard conforming compilers *strongly* favor an
533  * std::initalizer_list overload for construction if one exists.  The
534  * following is a simple tag used to disambiguate construction with
535  * initializer lists and regular uniform initialization.
536  *
537  * For example consider the following case
538  *
539  *  class Something {
540  *  public:
541  *    explicit Something(int);
542  *    Something(std::intiializer_list<int>);
543  *
544  *    operator int();
545  *  };
546  *
547  *  ...
548  *  Something something{1}; // SURPRISE!!
549  *
550  * The last call to instantiate the Something object will go to the
551  * initializer_list overload.  Which may be surprising to users.
552  *
553  * If however this tag was used to disambiguate such construction it would be
554  * easy for users to see which construction overload their code was referring
555  * to.  For example
556  *
557  *  class Something {
558  *  public:
559  *    explicit Something(int);
560  *    Something(folly::initlist_construct_t, std::initializer_list<int>);
561  *
562  *    operator int();
563  *  };
564  *
565  *  ...
566  *  Something something_one{1}; // not the initializer_list overload
567  *  Something something_two{folly::initlist_construct, {1}}; // correct
568  */
569 struct initlist_construct_t {};
570 constexpr initlist_construct_t initlist_construct{};
571
572 } // namespace folly
573
574 // gcc-5.0 changed string's implementation in libgcc to be non-relocatable
575 #if __GNUC__ < 5
576 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_3(std::basic_string)
577 #endif
578 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::vector)
579 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::list)
580 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::deque)
581 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_2(std::unique_ptr)
582 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(std::shared_ptr)
583 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(std::function)
584
585 // Boost
586 FOLLY_ASSUME_FBVECTOR_COMPATIBLE_1(boost::shared_ptr)
587
588 #define FOLLY_CREATE_HAS_MEMBER_TYPE_TRAITS(classname, type_name) \
589   template <typename T> \
590   struct classname { \
591     template <typename C> \
592     constexpr static bool test(typename C::type_name*) { return true; } \
593     template <typename> \
594     constexpr static bool test(...) { return false; } \
595     constexpr static bool value = test<T>(nullptr); \
596   }
597
598 #define FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, cv_qual) \
599   template <typename TTheClass_, typename RTheReturn_, typename... TTheArgs_> \
600   class classname<TTheClass_, RTheReturn_(TTheArgs_...) cv_qual> { \
601     template < \
602       typename UTheClass_, RTheReturn_ (UTheClass_::*)(TTheArgs_...) cv_qual \
603     > struct sfinae {}; \
604     template <typename UTheClass_> \
605     constexpr static bool test(sfinae<UTheClass_, &UTheClass_::func_name>*) \
606     { return true; } \
607     template <typename> \
608     constexpr static bool test(...) { return false; } \
609   public: \
610     constexpr static bool value = test<TTheClass_>(nullptr); \
611   }
612
613 /*
614  * The FOLLY_CREATE_HAS_MEMBER_FN_TRAITS is used to create traits
615  * classes that check for the existence of a member function with
616  * a given name and signature. It currently does not support
617  * checking for inherited members.
618  *
619  * Such classes receive two template parameters: the class to be checked
620  * and the signature of the member function. A static boolean field
621  * named `value` (which is also constexpr) tells whether such member
622  * function exists.
623  *
624  * Each traits class created is bound only to the member name, not to
625  * its signature nor to the type of the class containing it.
626  *
627  * Say you need to know if a given class has a member function named
628  * `test` with the following signature:
629  *
630  *    int test() const;
631  *
632  * You'd need this macro to create a traits class to check for a member
633  * named `test`, and then use this traits class to check for the signature:
634  *
635  * namespace {
636  *
637  * FOLLY_CREATE_HAS_MEMBER_FN_TRAITS(has_test_traits, test);
638  *
639  * } // unnamed-namespace
640  *
641  * void some_func() {
642  *   cout << "Does class Foo have a member int test() const? "
643  *     << boolalpha << has_test_traits<Foo, int() const>::value;
644  * }
645  *
646  * You can use the same traits class to test for a completely different
647  * signature, on a completely different class, as long as the member name
648  * is the same:
649  *
650  * void some_func() {
651  *   cout << "Does class Foo have a member int test()? "
652  *     << boolalpha << has_test_traits<Foo, int()>::value;
653  *   cout << "Does class Foo have a member int test() const? "
654  *     << boolalpha << has_test_traits<Foo, int() const>::value;
655  *   cout << "Does class Bar have a member double test(const string&, long)? "
656  *     << boolalpha << has_test_traits<Bar, double(const string&, long)>::value;
657  * }
658  *
659  * @author: Marcelo Juchem <marcelo@fb.com>
660  */
661 #define FOLLY_CREATE_HAS_MEMBER_FN_TRAITS(classname, func_name) \
662   template <typename, typename> class classname; \
663   FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, ); \
664   FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL(classname, func_name, const); \
665   FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL( \
666       classname, func_name, /* nolint */ volatile); \
667   FOLLY_CREATE_HAS_MEMBER_FN_TRAITS_IMPL( \
668       classname, func_name, /* nolint */ volatile const)