Pārlūkot izejas kodu

Factory function make_unique_resource() with std::reference_wrapper

added.
main
offa pirms 7 gadiem
vecāks
revīzija
a88ea2e20f
2 mainītis faili ar 14 papildinājumiem un 0 dzēšanām
  1. +6
    -0
      include/unique_resource.h
  2. +8
    -0
      test/UniqueResourceTest.cpp

+ 6
- 0
include/unique_resource.h Parādīt failu

@@ -207,6 +207,12 @@ namespace sr
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 Parādīt failu

@@ -265,3 +265,11 @@ TEST_CASE("make unique resource", "[UniqueResource]")
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);
}


Notiek ielāde…
Atcelt
Saglabāt