1 | #pragma once |
2 | |
3 | #include <utility> |
4 | |
5 | #include <nlohmann/detail/conversions/from_json.hpp> |
6 | #include <nlohmann/detail/conversions/to_json.hpp> |
7 | |
8 | namespace nlohmann |
9 | { |
10 | |
11 | template<typename, typename> |
12 | struct adl_serializer |
13 | { |
14 | /*! |
15 | @brief convert a JSON value to any value type |
16 | |
17 | This function is usually called by the `get()` function of the |
18 | @ref basic_json class (either explicit or via conversion operators). |
19 | |
20 | @param[in] j JSON value to read from |
21 | @param[in,out] val value to write to |
22 | */ |
23 | template<typename BasicJsonType, typename ValueType> |
24 | static auto from_json(BasicJsonType&& j, ValueType& val) noexcept( |
25 | noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val))) |
26 | -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void()) |
27 | { |
28 | ::nlohmann::from_json(std::forward<BasicJsonType>(j), val); |
29 | } |
30 | |
31 | /*! |
32 | @brief convert any value type to a JSON value |
33 | |
34 | This function is usually called by the constructors of the @ref basic_json |
35 | class. |
36 | |
37 | @param[in,out] j JSON value to write to |
38 | @param[in] val value to read from |
39 | */ |
40 | template <typename BasicJsonType, typename ValueType> |
41 | static auto to_json(BasicJsonType& j, ValueType&& val) noexcept( |
42 | noexcept(::nlohmann::to_json(j, std::forward<ValueType>(val)))) |
43 | -> decltype(::nlohmann::to_json(j, std::forward<ValueType>(val)), void()) |
44 | { |
45 | ::nlohmann::to_json(j, std::forward<ValueType>(val)); |
46 | } |
47 | }; |
48 | |
49 | } // namespace nlohmann |
50 | |