Skip to content

Commit fd48931

Browse files
ChristianTackeGSIdennisklein
authored andcommitted
document/test default behaviour of maybe_owning_ptr
The default behaviour is not an accidental side effect. So document and test it.
1 parent e41888e commit fd48931

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

fairroot/tools/FairMemory.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ struct optional_deleter
5151
* contain a reference (and thus not delete its content
5252
* on destruction).
5353
*
54+
* The default is an owning pointer, so that it can be used
55+
* just like a plain std::unique_ptr. It should be trivial to
56+
* switch to a plain one later, if the non-owning part is not
57+
* used any longer.
58+
*
5459
* \note Think twice before using this!
5560
*
5661
* It's mostly meant for cases, where FairRoot has a public API

fairroot/tools/tests/maybe_owning.cxx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ TEST_CASE("maybe_owning_ptr")
5454
REQUIRE(analyzer.destructed == 1);
5555
REQUIRE(analyzer.was_destructed('A'));
5656
}
57+
SECTION("unique_ptr style initialize and go out of scope")
58+
{
59+
{
60+
MaybeOwning other{item_a.release()};
61+
REQUIRE(!item_a);
62+
REQUIRE(other);
63+
REQUIRE(analyzer.destructed == 0);
64+
}
65+
REQUIRE(analyzer.destructed == 1);
66+
REQUIRE(analyzer.was_destructed('A'));
67+
}
5768
SECTION("Pass ownership and go out of scope")
5869
{
5970
{

0 commit comments

Comments
 (0)