From a1c30780b20ac758b7caab9eca23e37df11b0d39 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 29 Mar 2020 18:34:23 +0100 Subject: Allow implicit lazy pointer construction for suitable types --- libadhocutil/lazyPointer.h | 13 ++++--------- libadhocutil/unittests/testLazyPointer.cpp | 4 ++-- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/libadhocutil/lazyPointer.h b/libadhocutil/lazyPointer.h index bb41bc2..9188d24 100644 --- a/libadhocutil/lazyPointer.h +++ b/libadhocutil/lazyPointer.h @@ -26,24 +26,19 @@ class LazyPointer { /// @endcond /** Construct pointer with a factory function. */ - explicit LazyPointer(const Factory & f) : + // NOLINTNEXTLINE(hicpp-explicit-conversions) + LazyPointer(Factory f) : source(f) { } /** Construct pointer with an instance value. */ - explicit LazyPointer(const P & p) : + // NOLINTNEXTLINE(hicpp-explicit-conversions) + LazyPointer(P p) : source(p) { } - /** Construct pointer with an instance value. */ - template - explicit LazyPointer(T * p, typename std::enable_if::value>::type * = nullptr) : - source(P(p)) - { - } - /** Construct pointer with no factory or value. */ LazyPointer() : source(P(NULL)) diff --git a/libadhocutil/unittests/testLazyPointer.cpp b/libadhocutil/unittests/testLazyPointer.cpp index 1709742..31b92a5 100644 --- a/libadhocutil/unittests/testLazyPointer.cpp +++ b/libadhocutil/unittests/testLazyPointer.cpp @@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE ( islazy ) BOOST_AUTO_TEST_CASE ( preinit ) { Test * t = new Test(4); - TestLazyPointer p(t); + TestLazyPointer p(TestLazyPointer::pointer_type{ t }); BOOST_REQUIRE_EQUAL(true, p.hasValue()); BOOST_REQUIRE_EQUAL(p, t); BOOST_REQUIRE_EQUAL(4, p->val); @@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE ( preinit ) BOOST_AUTO_TEST_CASE ( reset ) { Test * t = new Test(4); - TestLazyPointer p(t); + TestLazyPointer p(TestLazyPointer::pointer_type{ t }); BOOST_REQUIRE_EQUAL(true, p.hasValue()); BOOST_REQUIRE_EQUAL(4, p->val); p = nullptr; -- cgit v1.2.3