adl_serializer.hpp 1.5 KB

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