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
52294b33
Unverified
Commit
52294b33
authored
6 years ago
by
Kenton Varda
Committed by
GitHub
6 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #805 from capnproto/fix-maybe-move-from-ref
`Maybe<T>(Maybe<T&>&&)` should do a copy, not a move.
parents
a6e331b4
132623f0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
common-test.c++
c++/src/kj/common-test.c++
+18
-0
common.h
c++/src/kj/common.h
+6
-0
No files found.
c++/src/kj/common-test.c++
View file @
52294b33
...
...
@@ -50,6 +50,15 @@ struct Immovable {
KJ_DISALLOW_COPY
(
Immovable
);
};
struct
CopyOrMove
{
// Type that detects the difference between copy and move.
CopyOrMove
(
int
i
)
:
i
(
i
)
{}
CopyOrMove
(
CopyOrMove
&&
other
)
:
i
(
other
.
i
)
{
i
=
-
1
;
}
CopyOrMove
(
const
CopyOrMove
&
)
=
default
;
int
i
;
};
TEST
(
Common
,
Maybe
)
{
{
Maybe
<
int
>
m
=
123
;
...
...
@@ -248,6 +257,15 @@ TEST(Common, Maybe) {
m
=
nullptr
;
KJ_EXPECT
(
m
==
nullptr
);
}
{
// Test that initializing Maybe<T> from Maybe<T&>&& does a copy, not a move.
CopyOrMove
x
(
123
);
Maybe
<
CopyOrMove
&>
m
(
x
);
Maybe
<
CopyOrMove
>
m2
=
kj
::
mv
(
m
);
KJ_EXPECT
(
KJ_ASSERT_NONNULL
(
m
).
i
==
123
);
KJ_EXPECT
(
KJ_ASSERT_NONNULL
(
m2
).
i
==
123
);
}
}
TEST
(
Common
,
MaybeConstness
)
{
...
...
This diff is collapsed.
Click to expand it.
c++/src/kj/common.h
View file @
52294b33
...
...
@@ -1121,6 +1121,12 @@ public:
}
}
template
<
typename
U
>
Maybe
(
Maybe
<
U
&>&&
other
)
{
KJ_IF_MAYBE
(
val
,
other
)
{
ptr
.
emplace
(
*
val
);
}
}
template
<
typename
U
>
Maybe
(
const
Maybe
<
U
>&
other
)
{
KJ_IF_MAYBE
(
val
,
other
)
{
ptr
.
emplace
(
*
val
);
...
...
This diff is collapsed.
Click to expand it.
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