AK: Prefer using instead of typedef

Problem:
- `typedef` is a keyword which comes from C and carries with it old
  syntax that is hard to read.
- Creating type aliases with the `using` keyword allows for easier
  future maintenance because it supports template syntax.
- There is inconsistent use of `typedef` vs `using`.

Solution:
- Use `clang-tidy`'s checker called `modernize-use-using` to update
  the syntax to use the newer syntax.
- Remove unused functions to make `clang-tidy` happy.
- This results in consistency within the codebase.
This commit is contained in:
Lenny Maiorani 2020-11-11 15:21:01 -07:00 committed by Andreas Kling
parent 6b97118e89
commit f5ced347e6
Notes: sideshowbarker 2024-07-19 01:25:47 +09:00
12 changed files with 83 additions and 93 deletions

View File

@ -66,7 +66,7 @@ namespace AK {
*/ */
template<typename T, bool Incr, bool Cmp, bool Bool, bool Flags, bool Shift, bool Arith, typename X> template<typename T, bool Incr, bool Cmp, bool Bool, bool Flags, bool Shift, bool Arith, typename X>
class DistinctNumeric { class DistinctNumeric {
typedef DistinctNumeric<T, Incr, Cmp, Bool, Flags, Shift, Arith, X> Self; using Self = DistinctNumeric<T, Incr, Cmp, Bool, Flags, Shift, Arith, X>;
public: public:
DistinctNumeric(T value) DistinctNumeric(T value)
@ -301,8 +301,8 @@ private:
} }
#define TYPEDEF_DISTINCT_NUMERIC_GENERAL(T, Incr, Cmp, Bool, Flags, Shift, Arith, NAME) \ #define TYPEDEF_DISTINCT_NUMERIC_GENERAL(T, Incr, Cmp, Bool, Flags, Shift, Arith, NAME) \
typedef DistinctNumeric<T, Incr, Cmp, Bool, Flags, Shift, Arith, struct __##NAME##_tag> NAME using NAME = DistinctNumeric<T, Incr, Cmp, Bool, Flags, Shift, Arith, struct __##NAME##_tag>;
#define TYPEDEF_DISTINCT_ORDERED_ID(T, NAME) TYPEDEF_DISTINCT_NUMERIC_GENERAL(T, false, true, true, false, false, false, NAME) #define TYPEDEF_DISTINCT_ORDERED_ID(T, NAME) TYPEDEF_DISTINCT_NUMERIC_GENERAL(T, false, true, true, false, false, false, NAME)
// TODO: Further typedef's? // TODO: Further type aliases?
using AK::DistinctNumeric; using AK::DistinctNumeric;

View File

@ -67,9 +67,9 @@ public:
} }
void remove_one_randomly() { m_table.remove(m_table.begin()); } void remove_one_randomly() { m_table.remove(m_table.begin()); }
typedef HashTable<Entry, EntryTraits> HashTableType; using HashTableType = HashTable<Entry, EntryTraits>;
typedef typename HashTableType::Iterator IteratorType; using IteratorType = typename HashTableType::Iterator;
typedef typename HashTableType::ConstIterator ConstIteratorType; using ConstIteratorType = typename HashTableType::ConstIterator;
IteratorType begin() { return m_table.begin(); } IteratorType begin() { return m_table.begin(); }
IteratorType end() { return m_table.end(); } IteratorType end() { return m_table.end(); }

View File

@ -45,7 +45,7 @@ class WeakPtr;
template<typename T> template<typename T>
class NonnullOwnPtr { class NonnullOwnPtr {
public: public:
typedef T ElementType; using ElementType = T;
enum AdoptTag { Adopt }; enum AdoptTag { Adopt };

View File

@ -32,8 +32,8 @@ namespace AK {
template<typename PtrType, int inline_capacity = 0> template<typename PtrType, int inline_capacity = 0>
class NonnullPtrVector : public Vector<PtrType, inline_capacity> { class NonnullPtrVector : public Vector<PtrType, inline_capacity> {
typedef typename PtrType::ElementType T; using T = typename PtrType::ElementType;
typedef Vector<PtrType, inline_capacity> Base; using Base = Vector<PtrType, inline_capacity>;
public: public:
NonnullPtrVector() NonnullPtrVector()

View File

@ -66,7 +66,7 @@ class NonnullRefPtr {
friend class WeakPtr; friend class WeakPtr;
public: public:
typedef T ElementType; using ElementType = T;
enum AdoptTag { Adopt }; enum AdoptTag { Adopt };

View File

@ -64,7 +64,7 @@ class RefCountedBase {
AK_MAKE_NONMOVABLE(RefCountedBase); AK_MAKE_NONMOVABLE(RefCountedBase);
public: public:
typedef unsigned int RefCountType; using RefCountType = unsigned int;
using AllowOwnPtr = FalseType; using AllowOwnPtr = FalseType;
ALWAYS_INLINE void ref() const ALWAYS_INLINE void ref() const
@ -111,16 +111,6 @@ public:
} }
}; };
static constexpr bool is_ref_counted(const RefCountedBase*)
{
return true;
}
static constexpr bool is_ref_counted(...)
{
return false;
}
} }
using AK::RefCounted; using AK::RefCounted;

View File

@ -128,7 +128,7 @@ struct RefPtrTraits {
static constexpr FlatPtr default_null_value = 0; static constexpr FlatPtr default_null_value = 0;
typedef std::nullptr_t NullType; using NullType = std::nullptr_t;
}; };
template<typename T, typename PtrTraits> template<typename T, typename PtrTraits>

View File

@ -104,48 +104,48 @@ struct EnableIf {
template<class T> template<class T>
struct EnableIf<true, T> { struct EnableIf<true, T> {
typedef T Type; using Type = T;
}; };
template<class T> template<class T>
struct AddConst { struct AddConst {
typedef const T Type; using Type = const T;
}; };
template<class T> template<class T>
struct RemoveConst { struct RemoveConst {
typedef T Type; using Type = T;
}; };
template<class T> template<class T>
struct RemoveConst<const T> { struct RemoveConst<const T> {
typedef T Type; using Type = T;
}; };
template<class T> template<class T>
struct RemoveVolatile { struct RemoveVolatile {
typedef T Type; using Type = T;
}; };
template<class T> template<class T>
struct RemoveVolatile<volatile T> { struct RemoveVolatile<volatile T> {
typedef T Type; using Type = T;
}; };
template<class T> template<class T>
struct RemoveCV { struct RemoveCV {
typedef typename RemoveVolatile<typename RemoveConst<T>::Type>::Type Type; using Type = typename RemoveVolatile<typename RemoveConst<T>::Type>::Type;
}; };
template<class T, T v> template<class T, T v>
struct IntegralConstant { struct IntegralConstant {
static constexpr T value = v; static constexpr T value = v;
typedef T ValueType; using ValueType = T;
typedef IntegralConstant Type; using Type = IntegralConstant;
constexpr operator ValueType() const { return value; } constexpr operator ValueType() const { return value; }
constexpr ValueType operator()() const { return value; } constexpr ValueType operator()() const { return value; }
}; };
typedef IntegralConstant<bool, false> FalseType; using FalseType = IntegralConstant<bool, false>;
typedef IntegralConstant<bool, true> TrueType; using TrueType = IntegralConstant<bool, true>;
template<typename...> template<typename...>
using VoidType = void; using VoidType = void;
@ -257,23 +257,23 @@ struct IsRvalueReference<T&&> : TrueType {
template<class T> template<class T>
struct RemovePointer { struct RemovePointer {
typedef T Type; using Type = T;
}; };
template<class T> template<class T>
struct RemovePointer<T*> { struct RemovePointer<T*> {
typedef T Type; using Type = T;
}; };
template<class T> template<class T>
struct RemovePointer<T* const> { struct RemovePointer<T* const> {
typedef T Type; using Type = T;
}; };
template<class T> template<class T>
struct RemovePointer<T* volatile> { struct RemovePointer<T* volatile> {
typedef T Type; using Type = T;
}; };
template<class T> template<class T>
struct RemovePointer<T* const volatile> { struct RemovePointer<T* const volatile> {
typedef T Type; using Type = T;
}; };
template<typename T, typename U> template<typename T, typename U>
@ -292,12 +292,12 @@ struct IsSame<T, T> {
template<bool condition, class TrueType, class FalseType> template<bool condition, class TrueType, class FalseType>
struct Conditional { struct Conditional {
typedef TrueType Type; using Type = TrueType;
}; };
template<class TrueType, class FalseType> template<class TrueType, class FalseType>
struct Conditional<false, TrueType, FalseType> { struct Conditional<false, TrueType, FalseType> {
typedef FalseType Type; using Type = FalseType;
}; };
template<typename T> template<typename T>
@ -306,15 +306,15 @@ struct IsNullPointer : IsSame<decltype(nullptr), typename RemoveCV<T>::Type> {
template<typename T> template<typename T>
struct RemoveReference { struct RemoveReference {
typedef T Type; using Type = T;
}; };
template<class T> template<class T>
struct RemoveReference<T&> { struct RemoveReference<T&> {
typedef T Type; using Type = T;
}; };
template<class T> template<class T>
struct RemoveReference<T&&> { struct RemoveReference<T&&> {
typedef T Type; using Type = T;
}; };
template<class T> template<class T>
@ -335,47 +335,47 @@ struct MakeUnsigned {
}; };
template<> template<>
struct MakeUnsigned<signed char> { struct MakeUnsigned<signed char> {
typedef unsigned char Type; using Type = unsigned char;
}; };
template<> template<>
struct MakeUnsigned<short> { struct MakeUnsigned<short> {
typedef unsigned short Type; using Type = unsigned short;
}; };
template<> template<>
struct MakeUnsigned<int> { struct MakeUnsigned<int> {
typedef unsigned Type; using Type = unsigned int;
}; };
template<> template<>
struct MakeUnsigned<long> { struct MakeUnsigned<long> {
typedef unsigned long Type; using Type = unsigned long;
}; };
template<> template<>
struct MakeUnsigned<long long> { struct MakeUnsigned<long long> {
typedef unsigned long long Type; using Type = unsigned long long;
}; };
template<> template<>
struct MakeUnsigned<unsigned char> { struct MakeUnsigned<unsigned char> {
typedef unsigned char Type; using Type = unsigned char;
}; };
template<> template<>
struct MakeUnsigned<unsigned short> { struct MakeUnsigned<unsigned short> {
typedef unsigned short Type; using Type = unsigned short;
}; };
template<> template<>
struct MakeUnsigned<unsigned int> { struct MakeUnsigned<unsigned int> {
typedef unsigned Type; using Type = unsigned int;
}; };
template<> template<>
struct MakeUnsigned<unsigned long> { struct MakeUnsigned<unsigned long> {
typedef unsigned long Type; using Type = unsigned long;
}; };
template<> template<>
struct MakeUnsigned<unsigned long long> { struct MakeUnsigned<unsigned long long> {
typedef unsigned long long Type; using Type = unsigned long long;
}; };
template<> template<>
struct MakeUnsigned<char> { struct MakeUnsigned<char> {
typedef unsigned char Type; using Type = unsigned char;
}; };
template<typename T> template<typename T>
@ -383,47 +383,47 @@ struct MakeSigned {
}; };
template<> template<>
struct MakeSigned<signed char> { struct MakeSigned<signed char> {
typedef signed char Type; using Type = signed char;
}; };
template<> template<>
struct MakeSigned<short> { struct MakeSigned<short> {
typedef short Type; using Type = short;
}; };
template<> template<>
struct MakeSigned<int> { struct MakeSigned<int> {
typedef int Type; using Type = int;
}; };
template<> template<>
struct MakeSigned<long> { struct MakeSigned<long> {
typedef long Type; using Type = long;
}; };
template<> template<>
struct MakeSigned<long long> { struct MakeSigned<long long> {
typedef long long Type; using Type = long long;
}; };
template<> template<>
struct MakeSigned<unsigned char> { struct MakeSigned<unsigned char> {
typedef char Type; using Type = char;
}; };
template<> template<>
struct MakeSigned<unsigned short> { struct MakeSigned<unsigned short> {
typedef short Type; using Type = short;
}; };
template<> template<>
struct MakeSigned<unsigned int> { struct MakeSigned<unsigned int> {
typedef int Type; using Type = int;
}; };
template<> template<>
struct MakeSigned<unsigned long> { struct MakeSigned<unsigned long> {
typedef long Type; using Type = long;
}; };
template<> template<>
struct MakeSigned<unsigned long long> { struct MakeSigned<unsigned long long> {
typedef long long Type; using Type = long long;
}; };
template<> template<>
struct MakeSigned<char> { struct MakeSigned<char> {
typedef signed char Type; using Type = signed char;
}; };
template<class T> template<class T>

View File

@ -31,7 +31,7 @@
TEST_CASE(construct) TEST_CASE(construct)
{ {
typedef HashMap<int, int> IntIntMap; using IntIntMap = HashMap<int, int>;
EXPECT(IntIntMap().is_empty()); EXPECT(IntIntMap().is_empty());
EXPECT_EQ(IntIntMap().size(), 0u); EXPECT_EQ(IntIntMap().size(), 0u);
} }

View File

@ -30,36 +30,36 @@
#include <AK/Platform.h> #include <AK/Platform.h>
#include <AK/StdLibExtras.h> #include <AK/StdLibExtras.h>
typedef __UINT64_TYPE__ u64; using u64 = __UINT64_TYPE__;
typedef __UINT32_TYPE__ u32; using u32 = __UINT32_TYPE__;
typedef __UINT16_TYPE__ u16; using u16 = __UINT16_TYPE__;
typedef __UINT8_TYPE__ u8; using u8 = __UINT8_TYPE__;
typedef __INT64_TYPE__ i64; using i64 = __INT64_TYPE__;
typedef __INT32_TYPE__ i32; using i32 = __INT32_TYPE__;
typedef __INT16_TYPE__ i16; using i16 = __INT16_TYPE__;
typedef __INT8_TYPE__ i8; using i8 = __INT8_TYPE__;
#ifdef __serenity__ #ifdef __serenity__
typedef __SIZE_TYPE__ size_t; using size_t = __SIZE_TYPE__;
typedef MakeSigned<size_t>::Type ssize_t; using ssize_t = MakeSigned<size_t>::Type;
typedef __PTRDIFF_TYPE__ ptrdiff_t; using ptrdiff_t = __PTRDIFF_TYPE__;
typedef __INTPTR_TYPE__ intptr_t; using intptr_t = __INTPTR_TYPE__;
typedef __UINTPTR_TYPE__ uintptr_t; using uintptr_t = __UINTPTR_TYPE__;
typedef u8 uint8_t; using uint8_t = u8;
typedef u16 uint16_t; using uint16_t = u16;
typedef u32 uint32_t; using uint32_t = u32;
typedef u64 uint64_t; using uint64_t = u64;
typedef i8 int8_t; using int8_t = i8;
typedef i16 int16_t; using int16_t = i16;
typedef i32 int32_t; using int32_t = i32;
typedef i64 int64_t; using int64_t = i64;
typedef int pid_t; using pid_t = int;
#else #else
# include <stddef.h> # include <stddef.h>
@ -67,19 +67,19 @@ typedef int pid_t;
# include <sys/types.h> # include <sys/types.h>
# ifdef __ptrdiff_t # ifdef __ptrdiff_t
typedef __PTRDIFF_TYPE__ __ptrdiff_t; using __ptrdiff_t = __PTRDIFF_TYPE__;
# endif # endif
#endif #endif
typedef Conditional<sizeof(void*) == 8, u64, u32>::Type FlatPtr; using FlatPtr = Conditional<sizeof(void*) == 8, u64, u32>::Type;
constexpr unsigned KiB = 1024; constexpr unsigned KiB = 1024;
constexpr unsigned MiB = KiB * KiB; constexpr unsigned MiB = KiB * KiB;
constexpr unsigned GiB = KiB * KiB * KiB; constexpr unsigned GiB = KiB * KiB * KiB;
namespace std { namespace std {
typedef decltype(nullptr) nullptr_t; using nullptr_t = decltype(nullptr);
} }
static constexpr u32 explode_byte(u8 b) static constexpr u32 explode_byte(u8 b)

View File

@ -81,7 +81,7 @@ private:
class Utf32View { class Utf32View {
public: public:
typedef Utf32CodepointIterator Iterator; using Iterator = Utf32CodepointIterator;
Utf32View() { } Utf32View() { }
Utf32View(const u32* code_points, size_t length) Utf32View(const u32* code_points, size_t length)

View File

@ -61,7 +61,7 @@ private:
class Utf8View { class Utf8View {
public: public:
typedef Utf8CodepointIterator Iterator; using Iterator = Utf8CodepointIterator;
Utf8View() { } Utf8View() { }
explicit Utf8View(const String&); explicit Utf8View(const String&);