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
e66aba4c
Commit
e66aba4c
authored
4 years ago
by
Simon Praetorius
Browse files
Options
Downloads
Patches
Plain Diff
Simplify ToUniquePtr deprecation
parent
f01a1041
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!912
Deprecate ToUniquePtr.
Pipeline
#35352
passed
4 years ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dune/common/test/CMakeLists.txt
+0
-4
0 additions, 4 deletions
dune/common/test/CMakeLists.txt
dune/common/test/to_unique_ptrtest.cc
+0
-96
0 additions, 96 deletions
dune/common/test/to_unique_ptrtest.cc
dune/common/to_unique_ptr.hh
+8
-86
8 additions, 86 deletions
dune/common/to_unique_ptr.hh
with
8 additions
and
186 deletions
dune/common/test/CMakeLists.txt
+
0
−
4
View file @
e66aba4c
...
...
@@ -392,10 +392,6 @@ dune_add_test(SOURCES transposetest.cc
LINK_LIBRARIES dunecommon
LABELS quick
)
dune_add_test
(
SOURCES to_unique_ptrtest.cc
LINK_LIBRARIES dunecommon
LABELS quick
)
dune_add_test
(
SOURCES tupleutilitytest.cc
LABELS quick
)
...
...
This diff is collapsed.
Click to expand it.
dune/common/test/to_unique_ptrtest.cc
deleted
100644 → 0
+
0
−
96
View file @
f01a1041
// -*- 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/deprecated.hh>
#include
<dune/common/to_unique_ptr.hh>
#include
<dune/common/test/testsuite.hh>
int
*
f_old
()
{
return
new
int
(
0
);
}
Dune
::
ToUniquePtr
<
int
>
f1
()
{
return
new
int
(
1
);
}
auto
f2
()
{
return
Dune
::
makeToUnique
<
int
>
(
1
);
}
struct
A
{
double
x
=
1.0
;
};
Dune
::
ToUniquePtr
<
A
>
g
()
{
return
new
A
{};
}
int
main
()
{
using
namespace
Dune
;
TestSuite
t
;
DUNE_NO_DEPRECATED_BEGIN
{
int
*
ptr
=
new
int
(
1
);
// test constructor
ToUniquePtr
<
int
>
w1
(
ptr
);
// test assignment from makeToUnique
ToUniquePtr
<
int
>
w2
=
makeToUnique
<
int
>
(
2
);
// test conversion to pointer
int
*
p1
=
f1
();
A
*
p2
=
g
();
delete
p1
;
delete
p2
;
// test conversion to unique_ptr
{
std
::
unique_ptr
<
int
>
u1
=
f1
();
std
::
unique_ptr
<
int
>
u2
=
f2
();
std
::
unique_ptr
<
A
>
u3
=
g
();
}
// test conversion to shared_ptr
{
std
::
shared_ptr
<
int
>
s1
=
f1
();
std
::
shared_ptr
<
A
>
s2
=
g
();
std
::
shared_ptr
<
int
>
s3
=
w2
;
t
.
check
(
!
bool
(
w2
))
<<
"w2 should be invalidated"
;
}
// test move assignment
{
ToUniquePtr
<
int
>
w3
(
new
int
(
3
)
);
w1
=
std
::
move
(
w3
);
t
.
check
(
!
bool
(
w3
))
<<
"w3 should be invalidated after move assignment"
;
}
t
.
check
(
bool
(
w1
))
<<
"w1 should not be invalidated"
;
// test move construction
{
ToUniquePtr
<
int
>
w4
(
std
::
move
(
w1
)
);
t
.
check
(
!
bool
(
w1
))
<<
"w1 should be invalidated after move construction"
;
}
// test management of ownership in ToUniquePtr
{
auto
w5
=
makeToUnique
<
int
>
(
5
);
// should free at the end of scope
}
// test unique_ptr-like interface of ToUniquePtr
auto
w6
=
makeToUnique
<
int
>
(
6
);
t
.
check
(
*
w6
==
6
)
<<
"Access to value of ToUniquePtr"
;
w6
.
reset
(
new
int
(
7
));
t
.
check
(
*
w6
==
7
)
<<
"Access to value of ToUniquePtr after reset"
;
w6
.
reset
();
t
.
check
(
!
bool
(
w6
))
<<
"w6 should be invalidated"
;
}
std
::
unique_ptr
<
int
>
x0
{
f_old
()
};
std
::
unique_ptr
<
int
>
x1
{
f1
()
};
std
::
unique_ptr
<
int
>
x2
=
f1
();
DUNE_NO_DEPRECATED_END
return
t
.
exit
();
}
This diff is collapsed.
Click to expand it.
dune/common/to_unique_ptr.hh
+
8
−
86
View file @
e66aba4c
...
...
@@ -4,101 +4,23 @@
#ifndef DUNE_TO_UNIQUE_PTR_HH
#define DUNE_TO_UNIQUE_PTR_HH
#warning to_unique_ptr.hh and ToUniquePtr
is
deprecated. Use std::unique_ptr or std::shared_ptr instead.
#warning to_unique_ptr.hh and ToUniquePtr
are
deprecated. Use std::unique_ptr or std::shared_ptr instead.
#include
<memory>
namespace
Dune
{
/// \brief An owning pointer wrapper that can be assigned to (smart) pointers. Cannot be copied.
/// Transfers ownership by cast to any (smart) pointer type. Releases the stored pointer on transfer.
/// NOTE: This is an intermediate solution to switch to std::unique_ptr in later releases smoothly.
/**
* \deprecated ToUniquePtr is deprecated and will be removed after Dune 2.8.
* Use std::unique_ptr or std::shared_ptr instead.
*
* Example of usage:
* ```
* ToUniquePtr<int> f() { return new int(1); }
* auto g() { return makeToUnique<int>(2); }
*
* int* p1 = f(); // p1 gets ownership, must delete explicitly
* delete p1;
*
* std::unique_ptr<int> p2 = f();
* std::shared_ptr<int> p3 = f();
*
* auto p4 = f(); // ToUniquePtr has itself pointer semantic
* std::cout << *p4 << '\n';
*
* std::unique_ptr<int> p5( g() );
* ```
**/
/// \brief Alias for `std::unique_ptr` introduced as transition wrapper.
/// \deprecated
template
<
class
T
>
class
[[
deprecated
(
"Will be removed after Dune 2.8. Use std::unique_ptr or std::shared_ptr instead."
)]]
ToUniquePtr
:
public
std
::
unique_ptr
<
T
>
{
using
Super
=
std
::
unique_ptr
<
T
>
;
public:
// Member types:
//@{
using
pointer
=
typename
Super
::
pointer
;
//@}
public:
// Constructors:
//@{
/// Constructor, stores the pointer.
ToUniquePtr
(
pointer
ptr
=
pointer
())
noexcept
:
Super
(
ptr
)
{}
/// Constructor, creates a `nullptr`
ToUniquePtr
(
std
::
nullptr_t
)
noexcept
:
Super
(
nullptr
)
{}
//@}
public
:
// Conversion operators:
//@{
/// Convert to underlying pointer, releases the stored pointer.
/// \deprecated Cast to raw pointer is deprecated. Use std::unique_ptr or std::shared_ptr instead.
/// Will be removed after Dune 2.8
[[
deprecated
(
"Cast to raw pointer is deprecated. Use std::unique_ptr or std::shared_ptr instead."
)]]
operator
pointer
()
noexcept
{
return
Super
::
release
();
}
/// Convert to unique_ptr, invalidates the stored pointer
operator
std
::
unique_ptr
<
T
>
()
noexcept
{
return
std
::
move
(
static_cast
<
Super
&>
(
*
this
));
}
/// Convert to shared_ptr, invalidates the stored pointer
operator
std
::
shared_ptr
<
T
>
()
noexcept
{
return
std
::
move
(
static_cast
<
Super
&>
(
*
this
));
}
/// Checks whether *this owns an object
explicit
operator
bool
()
noexcept
{
return
bool
(
static_cast
<
Super
&>
(
*
this
));
}
/// Checks whether *this owns an object
explicit
operator
bool
()
const
noexcept
{
return
bool
(
static_cast
<
Super
const
&>
(
*
this
));
}
//@}
};
using
ToUniquePtr
[[
deprecated
]]
=
std
::
unique_ptr
<
T
>
;
/// Constructs an object of type T and wraps it in a ToUniquePtr, \relates ToUniquePtr
/// \brief Alias for `std::make_unique` introduced as transition wrapper.
/// \deprecated
template
<
class
T
,
class
...
Args
>
ToU
nique
P
tr
<
T
>
makeToUnique
(
Args
&&
...
args
)
[[
deprecated
]]
std
::
u
nique
_p
tr
<
T
>
makeToUnique
(
Args
&&
...
args
)
{
return
{
new
T
(
std
::
forward
<
Args
>
(
args
)...)
}
;
return
std
::
make_unique
(
std
::
forward
<
Args
>
(
args
)...);
}
}
// end namespace Dune
...
...
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