Browse Source

Factory function make_unique_resource() with std::reference_wrapper

added.
main
offa 7 years ago
parent
commit
a88ea2e20f
2 changed files with 14 additions and 0 deletions
  1. +6
    -0
      include/unique_resource.h
  2. +8
    -0
      test/UniqueResourceTest.cpp

+ 6
- 0
include/unique_resource.h View File

return unique_resource<std::decay_t<R>, std::decay_t<D>>{std::forward<R>(r), std::forward<D>(d)}; return unique_resource<std::decay_t<R>, std::decay_t<D>>{std::forward<R>(r), std::forward<D>(d)};
} }


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


} }



+ 8
- 0
test/UniqueResourceTest.cpp View File

static_cast<void>(guard); static_cast<void>(guard);
} }


TEST_CASE("make unique resource with reference wrapper", "[UniqueResource]")
{
REQUIRE_CALL(m, deleter(3));
Handle h{3};
auto guard = sr::make_unique_resource(std::ref(h), deleter);
static_cast<void>(guard);
}


Loading…
Cancel
Save