1 #if SIMDJSON_SUPPORTS_DESERIALIZATION
3 #ifndef SIMDJSON_ONDEMAND_DESERIALIZE_H
4 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
5 #define SIMDJSON_ONDEMAND_DESERIALIZE_H
6 #include "simdjson/generic/ondemand/base.h"
7 #include "simdjson/generic/ondemand/array.h"
13 namespace tag_invoke_fn_ns {
16 struct tag_invoke_fn {
17 template <
typename Tag,
typename... Args>
18 requires requires(Tag tag, Args &&...args) {
19 tag_invoke(std::forward<Tag>(tag), std::forward<Args>(args)...);
21 constexpr
auto operator()(Tag tag, Args &&...args)
const
22 noexcept(noexcept(tag_invoke(std::forward<Tag>(tag),
23 std::forward<Args>(args)...)))
24 -> decltype(tag_invoke(std::forward<Tag>(tag),
25 std::forward<Args>(args)...)) {
26 return tag_invoke(std::forward<Tag>(tag), std::forward<Args>(args)...);
31 inline namespace tag_invoke_ns {
32 inline constexpr tag_invoke_fn_ns::tag_invoke_fn tag_invoke = {};
35 template <
typename Tag,
typename... Args>
36 concept tag_invocable = requires(Tag tag, Args... args) {
37 tag_invoke(std::forward<Tag>(tag), std::forward<Args>(args)...);
40 template <
typename Tag,
typename... Args>
41 concept nothrow_tag_invocable =
42 tag_invocable<Tag, Args...> && requires(Tag tag, Args... args) {
44 tag_invoke(std::forward<Tag>(tag), std::forward<Args>(args)...)
48 template <
typename Tag,
typename... Args>
49 using tag_invoke_result =
50 std::invoke_result<decltype(tag_invoke), Tag, Args...>;
52 template <
typename Tag,
typename... Args>
53 using tag_invoke_result_t =
54 std::invoke_result_t<decltype(tag_invoke), Tag, Args...>;
56 template <auto &Tag>
using tag_t = std::decay_t<decltype(Tag)>;
59 struct deserialize_tag;
62 template <
typename>
struct is_builtin_deserializable : std::false_type {};
63 template <>
struct is_builtin_deserializable<int64_t> : std::true_type {};
64 template <>
struct is_builtin_deserializable<uint64_t> : std::true_type {};
65 template <>
struct is_builtin_deserializable<double> : std::true_type {};
66 template <>
struct is_builtin_deserializable<bool> : std::true_type {};
67 template <>
struct is_builtin_deserializable<SIMDJSON_IMPLEMENTATION::ondemand::array> : std::true_type {};
68 template <>
struct is_builtin_deserializable<SIMDJSON_IMPLEMENTATION::ondemand::object> : std::true_type {};
69 template <>
struct is_builtin_deserializable<SIMDJSON_IMPLEMENTATION::ondemand::value> : std::true_type {};
70 template <>
struct is_builtin_deserializable<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> : std::true_type {};
71 template <>
struct is_builtin_deserializable<std::string_view> : std::true_type {};
74 concept is_builtin_deserializable_v = is_builtin_deserializable<T>::value;
76 template <
typename T,
typename ValT = SIMDJSON_IMPLEMENTATION::ondemand::value>
77 concept custom_deserializable = tag_invocable<deserialize_tag, ValT&, T&>;
79 template <
typename T,
typename ValT = SIMDJSON_IMPLEMENTATION::ondemand::value>
80 concept deserializable = custom_deserializable<T, ValT> || is_builtin_deserializable_v<T>;
82 template <
typename T,
typename ValT = SIMDJSON_IMPLEMENTATION::ondemand::value>
83 concept nothrow_custom_deserializable = nothrow_tag_invocable<deserialize_tag, ValT&, T&>;
86 template <
typename T,
typename ValT = SIMDJSON_IMPLEMENTATION::ondemand::value>
87 concept nothrow_deserializable = nothrow_custom_deserializable<T, ValT> || is_builtin_deserializable_v<T>;
90 inline constexpr
struct deserialize_tag {
91 using value_type = SIMDJSON_IMPLEMENTATION::ondemand::value;
92 using document_type = SIMDJSON_IMPLEMENTATION::ondemand::document;
93 using document_reference_type = SIMDJSON_IMPLEMENTATION::ondemand::document_reference;
97 requires custom_deserializable<T, value_type>
98 [[nodiscard]] constexpr
auto operator()(value_type &
object, T& output)
const noexcept(nothrow_custom_deserializable<T, value_type>) {
99 return tag_invoke(*
this,
object, output);
103 template <
typename T>
104 requires custom_deserializable<T, document_type>
105 [[nodiscard]] constexpr
auto operator()(document_type &
object, T& output)
const noexcept(nothrow_custom_deserializable<T, document_type>) {
106 return tag_invoke(*
this,
object, output);
110 template <
typename T>
111 requires custom_deserializable<T, document_reference_type>
112 [[nodiscard]] constexpr
auto operator()(document_reference_type &
object, T& output)
const noexcept(nothrow_custom_deserializable<T, document_reference_type>) {
113 return tag_invoke(*
this,
object, output);
The top level simdjson namespace, containing everything the library provides.