summaryrefslogtreecommitdiff
path: root/include/llvm/Support/Casting.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Support/Casting.h')
-rw-r--r--include/llvm/Support/Casting.h45
1 files changed, 23 insertions, 22 deletions
diff --git a/include/llvm/Support/Casting.h b/include/llvm/Support/Casting.h
index 89d2af052dc1..baa2a814e9a1 100644
--- a/include/llvm/Support/Casting.h
+++ b/include/llvm/Support/Casting.h
@@ -1,4 +1,4 @@
-//===-- llvm/Support/Casting.h - Allow flexible, checked, casts -*- C++ -*-===//
+//===- llvm/Support/Casting.h - Allow flexible, checked, casts --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -19,6 +19,7 @@
#include "llvm/Support/type_traits.h"
#include <cassert>
#include <memory>
+#include <type_traits>
namespace llvm {
@@ -31,18 +32,19 @@ namespace llvm {
// template selection process... the default implementation is a noop.
//
template<typename From> struct simplify_type {
- typedef From SimpleType; // The real type this represents...
+ using SimpleType = From; // The real type this represents...
// An accessor to get the real value...
static SimpleType &getSimplifiedValue(From &Val) { return Val; }
};
template<typename From> struct simplify_type<const From> {
- typedef typename simplify_type<From>::SimpleType NonConstSimpleType;
- typedef typename add_const_past_pointer<NonConstSimpleType>::type
- SimpleType;
- typedef typename add_lvalue_reference_if_not_pointer<SimpleType>::type
- RetType;
+ using NonConstSimpleType = typename simplify_type<From>::SimpleType;
+ using SimpleType =
+ typename add_const_past_pointer<NonConstSimpleType>::type;
+ using RetType =
+ typename add_lvalue_reference_if_not_pointer<SimpleType>::type;
+
static RetType getSimplifiedValue(const From& Val) {
return simplify_type<From>::getSimplifiedValue(const_cast<From&>(Val));
}
@@ -148,36 +150,35 @@ template <class X, class Y> LLVM_NODISCARD inline bool isa(const Y &Val) {
template<class To, class From> struct cast_retty;
-
// Calculate what type the 'cast' function should return, based on a requested
// type of To and a source type of From.
template<class To, class From> struct cast_retty_impl {
- typedef To& ret_type; // Normal case, return Ty&
+ using ret_type = To &; // Normal case, return Ty&
};
template<class To, class From> struct cast_retty_impl<To, const From> {
- typedef const To &ret_type; // Normal case, return Ty&
+ using ret_type = const To &; // Normal case, return Ty&
};
template<class To, class From> struct cast_retty_impl<To, From*> {
- typedef To* ret_type; // Pointer arg case, return Ty*
+ using ret_type = To *; // Pointer arg case, return Ty*
};
template<class To, class From> struct cast_retty_impl<To, const From*> {
- typedef const To* ret_type; // Constant pointer arg case, return const Ty*
+ using ret_type = const To *; // Constant pointer arg case, return const Ty*
};
template<class To, class From> struct cast_retty_impl<To, const From*const> {
- typedef const To* ret_type; // Constant pointer arg case, return const Ty*
+ using ret_type = const To *; // Constant pointer arg case, return const Ty*
};
template <class To, class From>
struct cast_retty_impl<To, std::unique_ptr<From>> {
private:
- typedef typename cast_retty_impl<To, From *>::ret_type PointerType;
- typedef typename std::remove_pointer<PointerType>::type ResultType;
+ using PointerType = typename cast_retty_impl<To, From *>::ret_type;
+ using ResultType = typename std::remove_pointer<PointerType>::type;
public:
- typedef std::unique_ptr<ResultType> ret_type;
+ using ret_type = std::unique_ptr<ResultType>;
};
template<class To, class From, class SimpleFrom>
@@ -185,19 +186,19 @@ struct cast_retty_wrap {
// When the simplified type and the from type are not the same, use the type
// simplifier to reduce the type, then reuse cast_retty_impl to get the
// resultant type.
- typedef typename cast_retty<To, SimpleFrom>::ret_type ret_type;
+ using ret_type = typename cast_retty<To, SimpleFrom>::ret_type;
};
template<class To, class FromTy>
struct cast_retty_wrap<To, FromTy, FromTy> {
// When the simplified type is equal to the from type, use it directly.
- typedef typename cast_retty_impl<To,FromTy>::ret_type ret_type;
+ using ret_type = typename cast_retty_impl<To,FromTy>::ret_type;
};
template<class To, class From>
struct cast_retty {
- typedef typename cast_retty_wrap<To, From,
- typename simplify_type<From>::SimpleType>::ret_type ret_type;
+ using ret_type = typename cast_retty_wrap<
+ To, From, typename simplify_type<From>::SimpleType>::ret_type;
};
// Ensure the non-simple values are converted using the simplify_type template
@@ -393,6 +394,6 @@ LLVM_NODISCARD inline auto unique_dyn_cast_or_null(std::unique_ptr<Y> &&Val)
return unique_dyn_cast_or_null<X, Y>(Val);
}
-} // End llvm namespace
+} // end namespace llvm
-#endif
+#endif // LLVM_SUPPORT_CASTING_H