adl_serializer.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 void from_json(BasicJsonType&& j, ValueType& val) noexcept(
  19. noexcept(::nlohmann::from_json(std::forward<BasicJsonType>(j), val)))
  20. {
  21. ::nlohmann::from_json(std::forward<BasicJsonType>(j), val);
  22. }
  23. /*!
  24. @brief convert any value type to a JSON value
  25. This function is usually called by the constructors of the @ref basic_json
  26. class.
  27. @param[in,out] j JSON value to write to
  28. @param[in] val value to read from
  29. */
  30. template<typename BasicJsonType, typename ValueType>
  31. static void to_json(BasicJsonType& j, ValueType&& val) noexcept(
  32. noexcept(::nlohmann::to_json(j, std::forward<ValueType>(val))))
  33. {
  34. ::nlohmann::to_json(j, std::forward<ValueType>(val));
  35. }
  36. };
  37. }