Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-15 08:37:17

0001 //
0002 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/json
0008 //
0009 
0010 #ifndef BOOST_JSON_IMPL_VISIT_HPP
0011 #define BOOST_JSON_IMPL_VISIT_HPP
0012 
0013 namespace boost {
0014 namespace json {
0015 
0016 
0017 template<class Visitor>
0018 auto
0019 visit(
0020     Visitor&& v,
0021     value& jv) -> decltype(
0022         static_cast<Visitor&&>(v)( std::declval<std::nullptr_t&>() ) )
0023 {
0024     switch(jv.kind())
0025     {
0026     default: // unreachable()?
0027     case kind::string:  return static_cast<Visitor&&>(v)( jv.get_string() );
0028     case kind::array:   return static_cast<Visitor&&>(v)( jv.get_array() );
0029     case kind::object:  return static_cast<Visitor&&>(v)( jv.get_object() );
0030     case kind::bool_:   return static_cast<Visitor&&>(v)( jv.get_bool() );
0031     case kind::int64:   return static_cast<Visitor&&>(v)( jv.get_int64() );
0032     case kind::uint64:  return static_cast<Visitor&&>(v)( jv.get_uint64() );
0033     case kind::double_: return static_cast<Visitor&&>(v)( jv.get_double() );
0034     case kind::null: {
0035         auto np = nullptr;
0036         return static_cast<Visitor&&>(v)(np) ;
0037     }
0038     }
0039 }
0040 
0041 template<class Visitor>
0042 auto
0043 visit(
0044     Visitor&& v,
0045     value const& jv) -> decltype(
0046         static_cast<Visitor&&>(v)( std::declval<std::nullptr_t const&>() ) )
0047 {
0048     switch(jv.kind())
0049     {
0050     default: // unreachable()?
0051     case kind::string:  return static_cast<Visitor&&>(v)( jv.get_string() );
0052     case kind::array:   return static_cast<Visitor&&>(v)( jv.get_array() );
0053     case kind::object:  return static_cast<Visitor&&>(v)( jv.get_object() );
0054     case kind::bool_:   return static_cast<Visitor&&>(v)( jv.get_bool() );
0055     case kind::int64:   return static_cast<Visitor&&>(v)( jv.get_int64() );
0056     case kind::uint64:  return static_cast<Visitor&&>(v)( jv.get_uint64() );
0057     case kind::double_: return static_cast<Visitor&&>(v)( jv.get_double() );
0058     case kind::null: {
0059         auto const np = nullptr;
0060         return static_cast<Visitor&&>(v)(np) ;
0061     }
0062     }
0063 }
0064 
0065 
0066 template<class Visitor>
0067 auto
0068 visit(
0069     Visitor&& v,
0070     value&& jv) -> decltype(
0071         static_cast<Visitor&&>(v)( std::declval<std::nullptr_t&&>() ) )
0072 {
0073     switch(jv.kind())
0074     {
0075     default: // unreachable()?
0076     case kind::string:  return static_cast<Visitor&&>(v)( std::move( jv.get_string() ) );
0077     case kind::array:   return static_cast<Visitor&&>(v)( std::move( jv.get_array() ) );
0078     case kind::object:  return static_cast<Visitor&&>(v)( std::move( jv.get_object() ) );
0079     case kind::bool_:   return static_cast<Visitor&&>(v)( std::move( jv.get_bool() ) );
0080     case kind::int64:   return static_cast<Visitor&&>(v)( std::move( jv.get_int64() ) );
0081     case kind::uint64:  return static_cast<Visitor&&>(v)( std::move( jv.get_uint64() ) );
0082     case kind::double_: return static_cast<Visitor&&>(v)( std::move( jv.get_double() ) );
0083     case kind::null:    return static_cast<Visitor&&>(v)( std::nullptr_t() ) ;
0084     }
0085 }
0086 
0087 } // namespace json
0088 } // namespace boost
0089 
0090 #endif