]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add universal ref ct
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 9 Jul 2026 12:06:59 +0000 (14:06 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 9 Jul 2026 12:07:20 +0000 (14:07 +0200)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
pdns/expected.hh
pdns/test-iputils_hh.cc

index 74128f67aea25277a136846e188905127e80a857..e4a29e7a4a1c0c2b5fc434e93175262c2ef35953 100644 (file)
@@ -30,7 +30,7 @@ template <class E>
 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<T, E>
 public:
   expected(const T& arg) :
     std::variant<T, E>(arg) {}
+  expected(T&& arg) :
+    std::variant<T, E>(std::forward<T>(arg)) {}
 
   expected(const unexpected<E>& arg) :
     std::variant<T, E>(arg.error()) {}
index 7789833cab02ea00e7f2f2a4982b00a40e86de7f..ea8f9d0b4e05de85d0d28c657bab0964380a4efe 100644 (file)
@@ -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<std::string, int> test1(str);
+  BOOST_ASSERT(!str.empty());
+
+  pdns::expected<std::string, int> test2("bar");
 }
 
 BOOST_AUTO_TEST_SUITE_END()