#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)
{ "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