visit.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/json
  8. //
  9. #ifndef BOOST_JSON_VISIT_HPP
  10. #define BOOST_JSON_VISIT_HPP
  11. #include <boost/json/detail/config.hpp>
  12. #include <boost/json/value.hpp>
  13. #include <utility>
  14. namespace boost {
  15. namespace json {
  16. /** Invoke a function object with the contents of a @ref value.
  17. Invokes `v` as if by `std::forward<Visitor>(v)( X )`, where `X` is
  18. For overloads **(1)** and **(2)**:
  19. @li `jv.get_array()` if `jv.is_array()`, or
  20. @li `jv.get_object()` if `jv.is_object()`, or
  21. @li `jv.get_string()` if `jv.is_string()`, or
  22. @li `jv.get_int64()` if `jv.is_int64()`, or
  23. @li `jv.get_uint64()` if `jv.is_uint64()`, or
  24. @li `jv.get_double()` if `jv.is_double()`, or
  25. @li `jv.get_bool()` if `jv.is_bool()`, or
  26. @li a `const` **(2)** or mutable **(1)** reference to an object of type
  27. `std::nullptr_t` if `jv.is_null()`.
  28. For overload **(3)**:
  29. @li `std::move( jv.get_array() )` if `jv.is_array()`, or
  30. @li `std::move( jv.get_object() )` if `jv.is_object()`, or
  31. @li `std::move( jv.get_string() )` if `jv.is_string()`, or
  32. @li `std::move( jv.get_int64() )` if `jv.is_int64()`, or
  33. @li `std::move( jv.get_uint64() )` if `jv.is_uint64()`, or
  34. @li `std::move( jv.get_double() )` if `jv.is_double()`, or
  35. @li `std::move( jv.get_bool() )` if `jv.is_bool()`, or
  36. @li `std::nullptr_t()` if `jv.is_null()`.
  37. @returns The value returned by `v`.
  38. @param v The visitation function to invoke
  39. @param jv The value to visit.
  40. @{
  41. */
  42. template<class Visitor>
  43. auto
  44. visit(
  45. Visitor&& v,
  46. value& jv) -> decltype(
  47. static_cast<Visitor&&>(v)( std::declval<std::nullptr_t&>() ) );
  48. template<class Visitor>
  49. auto
  50. visit(
  51. Visitor &&v,
  52. value const &jv) -> decltype(
  53. static_cast<Visitor&&>(v)( std::declval<std::nullptr_t const&>() ) );
  54. template<class Visitor>
  55. auto
  56. visit(
  57. Visitor &&v,
  58. value&& jv) -> decltype(
  59. static_cast<Visitor&&>(v)( std::declval<std::nullptr_t&&>() ) );
  60. /// @}
  61. } // namespace json
  62. } // namespace boost
  63. #include <boost/json/impl/visit.hpp>
  64. #endif