]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/json/test/value_to.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / json / test / value_to.cpp
index e1ee5faeb69a12f8502e13629ba9b31e9aa27b0b..f4d05fb97f52be6e87e5dce90a80ceca82f10e24 100644 (file)
 
 #include "test_suite.hpp"
 
+#include <array>
 #include <map>
 #include <unordered_map>
 #include <vector>
 
 BOOST_JSON_NS_BEGIN
 
+
+template <class T, class = void>
+struct can_apply_value_to
+    : std::false_type
+{
+};
+
+template <class T>
+struct can_apply_value_to<T, detail::void_t<decltype(
+    value_to<int>(std::declval<T>()))
+>>
+    : std::true_type
+{
+};
+
+BOOST_STATIC_ASSERT(!can_apply_value_to<int>::value);
+
+
 class value_to_test
 {
 public:
-    
+
     template<class T>
     void
     check(T t)
@@ -66,6 +85,33 @@ public:
             { "a", 1 }, {"b", 2}, {"c", 3}
         });
         check(std::vector<int>{1, 2, 3, 4});
+        check(std::make_pair(std::string("test"), 5));
+        check(std::make_tuple(std::string("outer"),
+            std::make_pair(std::string("test"), 5)));
+        check(std::map<int, int>
+        {
+            {2, 4}, {3, 9}, {5, 25}
+        });
+
+        {
+            std::array<int, 1000> arr;
+            arr.fill(0);
+            check(arr);
+        }
+
+        BOOST_TEST_THROWS(
+            (value_to<std::tuple<int, int>>(value{1, 2, 3})),
+            std::invalid_argument);
+        BOOST_TEST_THROWS(
+            (value_to<std::tuple<int, int, int, int>>(value{1, 2, 3})),
+            std::invalid_argument);
+
+        BOOST_TEST_THROWS(
+            (value_to<std::array<int, 4>>(value{1, 2, 3})),
+            std::invalid_argument);
+        BOOST_TEST_THROWS(
+            (value_to<std::array<int, 4>>(value{1, 2, 3, 4, 5})),
+            std::invalid_argument);
     }
 
     void