WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
type_traits.h
1 //===- llvm/Support/type_traits.h - Simplfied type traits -------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file provides useful additions to the standard type_traits library.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_SUPPORT_TYPE_TRAITS_H
15 #define LLVM_SUPPORT_TYPE_TRAITS_H
16 
17 #include <type_traits>
18 #include <utility>
19 
20 #ifndef __has_feature
21 #define LLVM_DEFINED_HAS_FEATURE
22 #define __has_feature(x) 0
23 #endif
24 
25 namespace llvm {
26 
29 template <typename T>
30 struct isPodLike {
31  // std::is_trivially_copyable is available in libc++ with clang, libstdc++
32  // that comes with GCC 5.
33 #if (__has_feature(is_trivially_copyable) && defined(_LIBCPP_VERSION)) || \
34  (defined(__GNUC__) && __GNUC__ >= 5)
35  // If the compiler supports the is_trivially_copyable trait use it, as it
36  // matches the definition of isPodLike closely.
37  static const bool value = std::is_trivially_copyable<T>::value;
38 #elif __has_feature(is_trivially_copyable)
39  // Use the internal name if the compiler supports is_trivially_copyable but we
40  // don't know if the standard library does. This is the case for clang in
41  // conjunction with libstdc++ from GCC 4.x.
42  static const bool value = __is_trivially_copyable(T);
43 #else
44  // If we don't know anything else, we can (at least) assume that all non-class
45  // types are PODs.
46  static const bool value = !std::is_class<T>::value;
47 #endif
48 };
49 
50 // std::pair's are pod-like if their elements are.
51 template<typename T, typename U>
52 struct isPodLike<std::pair<T, U> > {
53  static const bool value = isPodLike<T>::value && isPodLike<U>::value;
54 };
55 
62 template <typename T> class is_integral_or_enum {
63  typedef typename std::remove_reference<T>::type UnderlyingT;
64 
65 public:
66  static const bool value =
67  !std::is_class<UnderlyingT>::value && // Filter conversion operators.
68  !std::is_pointer<UnderlyingT>::value &&
69  !std::is_floating_point<UnderlyingT>::value &&
70  std::is_convertible<UnderlyingT, unsigned long long>::value;
71 };
72 
74 template<typename T, typename Enable = void>
75 struct add_lvalue_reference_if_not_pointer { typedef T &type; };
76 
77 template <typename T>
79  T, typename std::enable_if<std::is_pointer<T>::value>::type> {
80  typedef T type;
81 };
82 
85 template<typename T, typename Enable = void>
86 struct add_const_past_pointer { typedef const T type; };
87 
88 template <typename T>
90  T, typename std::enable_if<std::is_pointer<T>::value>::type> {
91  typedef const typename std::remove_pointer<T>::type *type;
92 };
93 
94 } // namespace llvm
95 
96 #ifdef LLVM_DEFINED_HAS_FEATURE
97 #undef __has_feature
98 #endif
99 
100 #endif
Metafunction that determines whether the given type is either an integral type or an enumeration type...
Definition: type_traits.h:62
If T is a pointer to X, return a pointer to const X.
Definition: type_traits.h:86
isPodLike - This is a type trait that is used to determine whether a given type can be copied around ...
Definition: StringRef.h:535
If T is a pointer, just return it. If it is not, return T&.
Definition: type_traits.h:75