Browse Source

Factory function make_unique_resource() fully implemented and Test

added.
main
offa 7 years ago
parent
commit
0d2e3da347
2 changed files with 12 additions and 3 deletions
  1. +5
    -3
      include/unique_resource.h
  2. +7
    -0
      test/UniqueResourceTest.cpp

+ 5
- 3
include/unique_resource.h View File

@@ -199,10 +199,12 @@ namespace sr
};


template<class Resource, class Deleter>
unique_resource<std::decay_t<Resource>, std::decay_t<Deleter>> make_unique_resource(Resource&& r, Deleter&& d)
template<class R, class D>
unique_resource<std::decay_t<R>, std::decay_t<D>> make_unique_resource(R&& r, D&& d)
noexcept(std::is_nothrow_constructible<std::decay_t<R>, R>::value
&& std::is_nothrow_constructible<std::decay_t<D>, D>::value)
{
return unique_resource<std::decay_t<Resource>, std::decay_t<Deleter>>{std::forward<Resource>(r), std::forward<Deleter>(d)};
return unique_resource<std::decay_t<R>, std::decay_t<D>>{std::forward<R>(r), std::forward<D>(d)};
}



+ 7
- 0
test/UniqueResourceTest.cpp View File

@@ -258,3 +258,10 @@ TEST_CASE("deleter access", "[UniqueResource]")
}
}

TEST_CASE("make unique resource", "[UniqueResource]")
{
REQUIRE_CALL(m, deleter(7));
auto guard = sr::make_unique_resource(Handle{7}, deleter);
static_cast<void>(guard);
}


Loading…
Cancel
Save