Browse Source

Default ctor for unique_resource implemented (#151).

main
offa 5 years ago
parent
commit
8e1bf537a4
3 changed files with 25 additions and 0 deletions
  1. +7
    -0
      include/unique_resource.h
  2. +13
    -0
      test/CallMocks.h
  3. +5
    -0
      test/UniqueResourceTest.cpp

+ 7
- 0
include/unique_resource.h View File

@@ -46,6 +46,13 @@ namespace sr
{
public:

unique_resource()
: resource(R{}, scope_exit{[] { }}),
deleter(D{}, scope_exit{[] { }}),
execute_on_reset(false)
{
}

template<class RR, class DD,
std::enable_if_t<(std::is_constructible_v<R ,RR> && std::is_constructible_v<D, DD>
&& (std::is_nothrow_constructible_v<R, RR> || std::is_constructible_v<R, RR&>)

+ 13
- 0
test/CallMocks.h View File

@@ -37,6 +37,19 @@ namespace mock
};


struct MoveableMock
{
static constexpr bool trompeloeil_movable_mock = true;

MAKE_CONST_MOCK1(deleter, void(Handle));

void operator()(Handle h) const
{
this->deleter(h);
}
};


struct ThrowOnCopyMock
{
ThrowOnCopyMock()

+ 5
- 0
test/UniqueResourceTest.cpp View File

@@ -38,6 +38,11 @@ namespace
}
}

TEST_CASE("default construction", "[UniqueResource]")
{
sr::unique_resource<int, MoveableMock> guard{};
}

TEST_CASE("construction with move", "[UniqueResource]")
{
REQUIRE_CALL(m, deleter(3));

Loading…
Cancel
Save