WPILibC++  unspecified
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 #include "llvm/Compiler.h"
21 
22 namespace llvm {
23 
26 template <typename T>
27 struct isPodLike {
28  // std::is_trivially_copyable is available in libc++ with clang, libstdc++
29  // that comes with GCC 5.
30 #if (__has_feature(is_trivially_copyable) && defined(_LIBCPP_VERSION)) || \
31  (defined(__GNUC__) && __GNUC__ >= 5)
32  // If the compiler supports the is_trivially_copyable trait use it, as it
33  // matches the definition of isPodLike closely.
34  static const bool value = std::is_trivially_copyable<T>::value;
35 #elif __has_feature(is_trivially_copyable)
36  // Use the internal name if the compiler supports is_trivially_copyable but we
37  // don't know if the standard library does. This is the case for clang in
38  // conjunction with libstdc++ from GCC 4.x.
39  static const bool value = __is_trivially_copyable(T);
40 #else
41  // If we don't know anything else, we can (at least) assume that all non-class
42  // types are PODs.
43  static const bool value = !std::is_class<T>::value;
44 #endif
45 };
46 
47 // std::pair's are pod-like if their elements are.
48 template<typename T, typename U>
49 struct isPodLike<std::pair<T, U> > {
50  static const bool value = isPodLike<T>::value && isPodLike<U>::value;
51 };
52 
60 template <typename T> class is_integral_or_enum {
61  typedef typename std::remove_reference<T>::type UnderlyingT;
62 
63 public:
64  static const bool value =
65  !std::is_class<UnderlyingT>::value && // Filter conversion operators.
66  !std::is_pointer<UnderlyingT>::value &&
67  !std::is_floating_point<UnderlyingT>::value &&
68  (std::is_enum<UnderlyingT>::value ||
69  std::is_convertible<UnderlyingT, unsigned long long>::value);
70 };
71 
73 template<typename T, typename Enable = void>
74 struct add_lvalue_reference_if_not_pointer { typedef T &type; };
75 
76 template <typename T>
78  T, typename std::enable_if<std::is_pointer<T>::value>::type> {
79  typedef T type;
80 };
81 
84 template<typename T, typename Enable = void>
85 struct add_const_past_pointer { typedef const T type; };
86 
87 template <typename T>
89  T, typename std::enable_if<std::is_pointer<T>::value>::type> {
90  typedef const typename std::remove_pointer<T>::type *type;
91 };
92 
93 } // namespace llvm
94 
95 #endif
Definition: Path.inc:31
Definition: json.cpp:1170
Metafunction that determines whether the given type is either an integral type or an enumeration type...
Definition: type_traits.h:60
If T is a pointer to X, return a pointer to const X.
Definition: type_traits.h:85
isPodLike - This is a type trait that is used to determine whether a given type can be copied around ...
Definition: Optional.h:147
If T is a pointer, just return it. If it is not, return T&.
Definition: type_traits.h:74