• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //     __ _____ _____ _____
2 //  __|  |   __|     |   | |  JSON for Modern C++
3 // |  |  |__   |  |  | | | |  version 3.11.2
4 // |_____|_____|_____|_|___|  https://github.com/nlohmann/json
5 //
6 // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann <https://nlohmann.me>
7 // SPDX-License-Identifier: MIT
8 
9 #pragma once
10 
11 #include <utility>
12 
13 #include <nlohmann/detail/abi_macros.hpp>
14 #include <nlohmann/detail/conversions/from_json.hpp>
15 #include <nlohmann/detail/conversions/to_json.hpp>
16 #include <nlohmann/detail/meta/identity_tag.hpp>
17 
18 NLOHMANN_JSON_NAMESPACE_BEGIN
19 
20 /// @sa https://json.nlohmann.me/api/adl_serializer/
21 template<typename ValueType, typename>
22 struct adl_serializer
23 {
24     /// @brief convert a JSON value to any value type
25     /// @sa https://json.nlohmann.me/api/adl_serializer/from_json/
26     template<typename BasicJsonType, typename TargetType = ValueType>
from_jsonadl_serializer27     static auto from_json(BasicJsonType && j, TargetType& val) noexcept(
28         noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
29     -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), val), void())
30     {
31         ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
32     }
33 
34     /// @brief convert a JSON value to any value type
35     /// @sa https://json.nlohmann.me/api/adl_serializer/from_json/
36     template<typename BasicJsonType, typename TargetType = ValueType>
from_jsonadl_serializer37     static auto from_json(BasicJsonType && j) noexcept(
38     noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {})))
39     -> decltype(::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {}))
40     {
41         return ::nlohmann::from_json(std::forward<BasicJsonType>(j), detail::identity_tag<TargetType> {});
42     }
43 
44     /// @brief convert any value type to a JSON value
45     /// @sa https://json.nlohmann.me/api/adl_serializer/to_json/
46     template<typename BasicJsonType, typename TargetType = ValueType>
to_jsonadl_serializer47     static auto to_json(BasicJsonType& j, TargetType && val) noexcept(
48         noexcept(::nlohmann::to_json(j, std::forward<TargetType>(val))))
49     -> decltype(::nlohmann::to_json(j, std::forward<TargetType>(val)), void())
50     {
51         ::nlohmann::to_json(j, std::forward<TargetType>(val));
52     }
53 };
54 
55 NLOHMANN_JSON_NAMESPACE_END
56