Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
d1e80b34
Commit
d1e80b34
authored
Jun 01, 2017
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow comparing arrays with different element types.
parent
18e3c9f1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
+32
-0
common-test.c++
c++/src/kj/common-test.c++
+21
-0
common.h
c++/src/kj/common.h
+11
-0
No files found.
c++/src/kj/common-test.c++
View file @
d1e80b34
...
...
@@ -471,6 +471,27 @@ TEST(Common, ArrayAsBytes) {
}
}
KJ_TEST
(
"ArrayPtr operator =="
)
{
KJ_EXPECT
(
ArrayPtr
<
const
int
>
({
123
,
456
})
==
ArrayPtr
<
const
int
>
({
123
,
456
}));
KJ_EXPECT
(
!
(
ArrayPtr
<
const
int
>
({
123
,
456
})
!=
ArrayPtr
<
const
int
>
({
123
,
456
})));
KJ_EXPECT
(
ArrayPtr
<
const
int
>
({
123
,
456
})
!=
ArrayPtr
<
const
int
>
({
123
,
321
}));
KJ_EXPECT
(
ArrayPtr
<
const
int
>
({
123
,
456
})
!=
ArrayPtr
<
const
int
>
({
123
}));
KJ_EXPECT
(
ArrayPtr
<
const
int
>
({
123
,
456
})
==
ArrayPtr
<
const
short
>
({
123
,
456
}));
KJ_EXPECT
(
!
(
ArrayPtr
<
const
int
>
({
123
,
456
})
!=
ArrayPtr
<
const
short
>
({
123
,
456
})));
KJ_EXPECT
(
ArrayPtr
<
const
int
>
({
123
,
456
})
!=
ArrayPtr
<
const
short
>
({
123
,
321
}));
KJ_EXPECT
(
ArrayPtr
<
const
int
>
({
123
,
456
})
!=
ArrayPtr
<
const
short
>
({
123
}));
KJ_EXPECT
((
ArrayPtr
<
const
StringPtr
>
({
"foo"
,
"bar"
})
==
ArrayPtr
<
const
char
*
const
>
({
"foo"
,
"bar"
})));
KJ_EXPECT
(
!
(
ArrayPtr
<
const
StringPtr
>
({
"foo"
,
"bar"
})
!=
ArrayPtr
<
const
char
*
const
>
({
"foo"
,
"bar"
})));
KJ_EXPECT
((
ArrayPtr
<
const
StringPtr
>
({
"foo"
,
"bar"
})
!=
ArrayPtr
<
const
char
*
const
>
({
"foo"
,
"baz"
})));
KJ_EXPECT
((
ArrayPtr
<
const
StringPtr
>
({
"foo"
,
"bar"
})
!=
ArrayPtr
<
const
char
*
const
>
({
"foo"
})));
}
KJ_TEST
(
"kj::range()"
)
{
uint
expected
=
5
;
for
(
uint
i
:
range
(
5
,
10
))
{
...
...
c++/src/kj/common.h
View file @
d1e80b34
...
...
@@ -1331,6 +1331,17 @@ public:
}
inline
bool
operator
!=
(
const
ArrayPtr
&
other
)
const
{
return
!
(
*
this
==
other
);
}
template
<
typename
U
>
inline
bool
operator
==
(
const
ArrayPtr
<
U
>&
other
)
const
{
if
(
size_
!=
other
.
size
())
return
false
;
for
(
size_t
i
=
0
;
i
<
size_
;
i
++
)
{
if
(
ptr
[
i
]
!=
other
[
i
])
return
false
;
}
return
true
;
}
template
<
typename
U
>
inline
bool
operator
!=
(
const
ArrayPtr
<
U
>&
other
)
const
{
return
!
(
*
this
==
other
);
}
private
:
T
*
ptr
;
size_t
size_
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment