-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathReplaceTypedefWithTypeAlias.cpp
More file actions
78 lines (65 loc) · 1.78 KB
/
ReplaceTypedefWithTypeAlias.cpp
File metadata and controls
78 lines (65 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "Require.h"
#include <iostream>
#include <string>
#include <vector>
namespace ReplaceTypedefWithTypeAlias
{
struct Foo
{
void f()
{
m_x = 2;
}
int g(int x)
{
return x;
}
int m_x{1};
};
// #TEST#: RTDTA1 Replace typedef with type alias
typedef int IntT;
// #TEST#: RTDTA2 Replace typedef with type alias
typedef std::string StringT;
// #TEST#: RTDTA3 Replace typedef with type alias
typedef std::vector<StringT> StringVecT;
// #TEST#: RTDTA4 Replace typedef with type alias
typedef void (Foo::*FooFn)();
// #TEST#: RTDTA5 Replace typedef with type alias
typedef int (Foo::*FooGn)(int x);
} // namespace ReplaceTypedefWithTypeAlias
static std::ostream &operator<<(std::ostream &str, ReplaceTypedefWithTypeAlias::StringVecT::const_iterator &it)
{
if (it == ReplaceTypedefWithTypeAlias::StringVecT::const_iterator())
{
return str << "(end)";
}
return str << "(iterator)";
}
namespace
{
void f1()
{
// #TEST#: RTDTA6 Replace typedef with type alias
typedef int IntT;
IntT x{10};
REQUIRE_EQUAL(10, x);
ReplaceTypedefWithTypeAlias::StringVecT v;
using ReplaceTypedefWithTypeAlias::StringVecT;
const StringVecT::const_iterator begin = v.cbegin();
// #TEST#: RTDTA7 Replace typedef with type alias
typedef StringVecT::const_iterator ConstIteratorT;
const ConstIteratorT end = v.cend();
REQUIRE_EQUAL(end, begin);
ReplaceTypedefWithTypeAlias::Foo f;
ReplaceTypedefWithTypeAlias::FooFn fn = &ReplaceTypedefWithTypeAlias::Foo::f;
(f.*fn)();
REQUIRE_EQUAL(2, f.m_x);
ReplaceTypedefWithTypeAlias::FooGn gn = &ReplaceTypedefWithTypeAlias::Foo::g;
const int x2 = (f.*gn)(1);
REQUIRE_EQUAL(1, x2);
}
} // namespace
void TestReplaceTypedefWithTypeAlias()
{
f1();
}