visit.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // Copyright (c) 2019 Vinnie Falco ([email protected])
  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 <type_traits>
  14. #include <utility>
  15. namespace boost {
  16. namespace json {
  17. /** Invoke a function object with the contents of a @ref value
  18. Invokes `v` as if by `std::forward<Visitor>(v)( X )`, where `X` is
  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 reference to an object of type `std::nullptr_t` if `jv.is_null()`.
  27. @return The value returned by Visitor.
  28. @param v The visitation function to invoke
  29. @param jv The value to visit.
  30. */
  31. template<class Visitor>
  32. auto
  33. visit(
  34. Visitor&& v,
  35. value& jv) -> decltype(
  36. static_cast<Visitor&&>(v)( std::declval<std::nullptr_t&>() ) );
  37. /** Invoke a function object with the contents of a @ref value
  38. Invokes `v` as if by `std::forward<Visitor>(v)( X )`, where `X` is
  39. @li `jv.get_array()` if `jv.is_array()`, or
  40. @li `jv.get_object()` if `jv.is_object()`, or
  41. @li `jv.get_string()` if `jv.is_string()`, or
  42. @li `jv.get_int64()` if `jv.is_int64()`, or
  43. @li `jv.get_uint64()` if `jv.is_uint64()`, or
  44. @li `jv.get_double()` if `jv.is_double()`, or
  45. @li `jv.get_bool()` if `jv.is_bool()`, or
  46. @li reference to an object of type `const std::nullptr_t` if `jv.is_null()`.
  47. @return The value returned by Visitor.
  48. @param v The visitation function to invoke
  49. @param jv The value to visit.
  50. */
  51. template<class Visitor>
  52. auto
  53. visit(
  54. Visitor &&v,
  55. value const &jv) -> decltype(
  56. static_cast<Visitor&&>(v)( std::declval<std::nullptr_t const&>() ) );
  57. /** Invoke a function object with the contents of a @ref value
  58. Invokes `v` as if by `std::forward<Visitor>(v)( X )`, where `X` is
  59. @li `std::move( jv.get_array() )` if `jv.is_array()`, or
  60. @li `std::move( jv.get_object() )` if `jv.is_object()`, or
  61. @li `std::move( jv.get_string() )` if `jv.is_string()`, or
  62. @li `std::move( jv.get_int64() )` if `jv.is_int64()`, or
  63. @li `std::move( jv.get_uint64() )` if `jv.is_uint64()`, or
  64. @li `std::move( jv.get_double() )` if `jv.is_double()`, or
  65. @li `std::move( jv.get_bool() )` if `jv.is_bool()`, or
  66. @li `std::nullptr_t()` if `jv.is_null()`.
  67. @return The value returned by Visitor.
  68. @param v The visitation function to invoke
  69. @param jv The value to visit.
  70. */
  71. template<class Visitor>
  72. auto
  73. visit(
  74. Visitor &&v,
  75. value&& jv) -> decltype(
  76. static_cast<Visitor&&>(v)( std::declval<std::nullptr_t&&>() ) );
  77. } // namespace json
  78. } // namespace boost
  79. #include <boost/json/impl/visit.hpp>
  80. #endif