diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2020-03-29 18:34:23 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2020-03-29 18:34:23 +0100 |
commit | a1c30780b20ac758b7caab9eca23e37df11b0d39 (patch) | |
tree | 14c053bdf0abd1a8050761d17b3a7e33c7bd3c1c | |
parent | Add more C++ special member helpers (diff) | |
download | libadhocutil-a1c30780b20ac758b7caab9eca23e37df11b0d39.tar.bz2 libadhocutil-a1c30780b20ac758b7caab9eca23e37df11b0d39.tar.xz libadhocutil-a1c30780b20ac758b7caab9eca23e37df11b0d39.zip |
Allow implicit lazy pointer construction for suitable types
-rw-r--r-- | libadhocutil/lazyPointer.h | 13 | ||||
-rw-r--r-- | 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 <typename TT = T> - explicit LazyPointer(T * p, typename std::enable_if<!std::is_same<TT *, P>::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; |