Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Core Modules
dune-common
Commits
15ae0f30
Commit
15ae0f30
authored
5 years ago
by
Santiago Ospina De Los Ríos
Committed by
Christoph Grüninger
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Include test for identity
parent
7affda68
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!696
Support std::identity
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dune/common/test/CMakeLists.txt
+3
-0
3 additions, 0 deletions
dune/common/test/CMakeLists.txt
dune/common/test/stdidentity.cc
+48
-0
48 additions, 0 deletions
dune/common/test/stdidentity.cc
with
51 additions
and
0 deletions
dune/common/test/CMakeLists.txt
+
3
−
0
View file @
15ae0f30
...
...
@@ -306,6 +306,9 @@ dune_add_test(SOURCES singletontest.cc
dune_add_test
(
SOURCES sllisttest.cc
LABELS quick
)
dune_add_test
(
SOURCES stdidentity.cc
LABELS quick
)
dune_add_test
(
SOURCES stdapplytest.cc
LINK_LIBRARIES dunecommon
LABELS quick
)
...
...
This diff is collapsed.
Click to expand it.
dune/common/test/stdidentity.cc
0 → 100644
+
48
−
0
View file @
15ae0f30
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifdef HAVE_CONFIG_H
#include
"config.h"
#endif
#include
<dune/common/std/functional.hh>
#include
<iostream>
#include
<cassert>
struct
Foo
{
static
int
count
;
Foo
()
{
++
count
;
std
::
cout
<<
"construct"
<<
std
::
endl
;
}
Foo
(
const
Foo
&
)
{
++
count
;
std
::
cout
<<
"copy construct"
<<
std
::
endl
;
}
Foo
(
Foo
&&
)
{
++
count
;
std
::
cout
<<
"move construct"
<<
std
::
endl
;
}
~
Foo
()
{
--
count
;
std
::
cout
<<
"deconstruct"
<<
std
::
endl
;
}
};
int
Foo
::
count
=
0
;
template
<
typename
T
>
T
&&
assert_count
(
T
&&
arg
,
int
count
)
{
std
::
cout
<<
std
::
decay_t
<
T
>::
count
<<
std
::
endl
;
assert
(
std
::
decay_t
<
T
>::
count
==
count
);
return
std
::
forward
<
T
>
(
arg
);
}
int
main
()
{
auto
id
=
Dune
::
Std
::
identity
();
assert_count
(
id
(
Foo
()),
1
);
// pass an r-value to identity, still constructed on the assert
const
auto
&
foo0
=
id
(
Foo
());
// pass an r-value to identity
assert_count
(
foo0
,
0
);
// id(Foo()) is alredy doconstructed at this point
auto
foo1
=
id
(
Foo
());
// pass an r-value to identity and move it to foo1
assert_count
(
foo1
,
1
);
// foo0 is alredy doconstructed at this point
Foo
foo2
;
assert_count
(
id
(
foo2
),
2
);
// pass an l-value to identity
const
auto
&
foo3
=
id
(
foo2
);
// pass an l-value to identity
assert_count
(
foo3
,
2
);
// foo still exist at this point
auto
foo4
=
id
(
foo2
);
// pass an l-value to identity and copy its result
assert_count
(
foo4
,
3
);
// copy of foo still exist at this point
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment