FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
co-cpp19/src/array19.lib/array19/AllocatedArrayOf.test.cpp at develop · basicpp/co-cpp19 · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
basicpp
/
co-cpp19
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
14
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
co-cpp19
/
src
/
array19.lib
/
array19
/
AllocatedArrayOf.test.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
88 lines (64 loc) · 2.05 KB
Breadcrumbs
co-cpp19
/
src
/
array19.lib
/
array19
/
AllocatedArrayOf.test.cpp
Copy path
File metadata and controls
88 lines (64 loc) · 2.05 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
79
80
81
82
83
84
85
86
87
88
#
include
"
AllocatedArrayOf.h
"
#
include
"
AllocatedArrayOf.equals.h
"
#
include
"
AllocatedArrayOf.ostream.h
"
#
include
"
SliceOf.carray.h
"
#
include
"
SliceOf.equals.h
"
#
include
"
SliceOf.ostream.h
"
#
include
<
gtest/gtest.h
>
#
include
<
utility
>
using
namespace
array19
;
TEST
(AllocatedArrayOf, construct) {
auto
v = AllocatedArrayOf{
1
,
2
,
3
};
ASSERT_EQ
(
sliceOfCArray
({
1
,
2
,
3
}), SliceOf{v});
}
namespace
{
struct
NonTrivial
;
using
NonTrivialArray = AllocatedArrayOf<NonTrivial>;
struct
User
{
NonTrivialArray v;
User
() =
default
;
};
struct
NonTrivial
{
NonTrivial
() : v(
1
) {}
explicit
NonTrivial
(
int
v) : v(v) {}
NonTrivial
(
const
NonTrivial& o) : v(o.v) {}
NonTrivial&
operator
=(
const
NonTrivial& o) {
return
v = o.
v
, *
this
; }
NonTrivial
(NonTrivial&& o)
noexcept
: v(o.v) {}
NonTrivial&
operator
=(NonTrivial&& o)
noexcept
{
return
v = o.
v
, *
this
; }
~NonTrivial
()
noexcept
{ c =
false
; }
bool
operator
==(
const
NonTrivial&)
const
=
default
;
int
value
()
const
{
return
v; }
private:
bool
c{
true
};
int
v;
};
[[maybe_unused]]
auto
operator
<<(std::ostream& out,
const
NonTrivial& c) -> std::ostream& {
return
out << c.
value
(); }
}
//
namespace
TEST
(AllocatedArrayOf, NontrivialExample) {
auto
v = AllocatedArrayOf<NonTrivial>{};
EXPECT_TRUE
(v.
isEmpty
());
ASSERT_EQ
(v.
count
(),
0u
);
v = AllocatedArrayOf{NonTrivial{}, NonTrivial{
2
}};
ASSERT_EQ
(v.
count
(),
2u
);
auto
v2 = v;
ASSERT_EQ
(v, v2);
}
TEST
(AllocatedArrayOf, MoveAssignAfterMove) {
using
E = NonTrivial;
using
AA
= AllocatedArrayOf<E>;
auto
v =
AA
{E{
1
}};
auto
v2 =
std::move
(v);
ASSERT_EQ
(v2, (
AA
{E{
1
}}));
v =
AA
{E{
2
}, E{
3
}};
ASSERT_EQ
(v, (
AA
{E{
2
}, E{
3
}}));
}
TEST
(AllocatedArrayOf, CopyAssignAfterMove) {
using
E = NonTrivial;
using
AA
= AllocatedArrayOf<E>;
auto
v =
AA
{E{
1
}};
auto
v2 =
std::move
(v);
ASSERT_EQ
(v2, (
AA
{E{
1
}}));
auto
v3 =
AA
{E{
2
}, E{
3
}};
v = v3;
ASSERT_EQ
(v, (
AA
{E{
2
}, E{
3
}}));
}
Back
|
FazBrowse Home
|
New Git URL