From: Otto Moerbeek Date: Thu, 9 Jul 2026 12:06:59 +0000 (+0200) Subject: Add universal ref ct X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=2bfcb7cbdb3288022e643dbde87db63b2fc0e0e0;p=thirdparty%2Fpdns.git Add universal ref ct Signed-off-by: Otto Moerbeek --- diff --git a/pdns/expected.hh b/pdns/expected.hh index 74128f67ae..e4a29e7a4a 100644 --- a/pdns/expected.hh +++ b/pdns/expected.hh @@ -30,7 +30,7 @@ template class unexpected { public: - unexpected(const E& arg) : + explicit unexpected(const E& arg) : err(arg) {} const E& error() const { @@ -47,6 +47,8 @@ class expected : private std::variant public: expected(const T& arg) : std::variant(arg) {} + expected(T&& arg) : + std::variant(std::forward(arg)) {} expected(const unexpected& arg) : std::variant(arg.error()) {} diff --git a/pdns/test-iputils_hh.cc b/pdns/test-iputils_hh.cc index 7789833cab..ea8f9d0b4e 100644 --- a/pdns/test-iputils_hh.cc +++ b/pdns/test-iputils_hh.cc @@ -984,6 +984,12 @@ BOOST_AUTO_TEST_CASE(test_expected) test = pdns::unexpected(3); BOOST_ASSERT(!test.has_value()); BOOST_CHECK_EQUAL(test.error(), 3); + + std::string str("foo"); + pdns::expected test1(str); + BOOST_ASSERT(!str.empty()); + + pdns::expected test2("bar"); } BOOST_AUTO_TEST_SUITE_END()