JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
jsonv::value::basic_object_reference< TValue > Struct Template Reference

What dereferencing an object_iterator (TValue of value) or a const_object_iterator (TValue of const value) gives: references to the key and value of one member. More...

#include <jsonv/value.hpp>

+ Collaboration diagram for jsonv::value::basic_object_reference< TValue >:

Public Types

using first_type = const std::string
 The type of first, as in std::pair, which this stands in for.
 
using second_type = TValue
 The type of second, as in std::pair.
 

Public Member Functions

 basic_object_reference (const std::string &key, TValue &val) noexcept
 Refer to key and val.
 
 basic_object_reference (std::conditional_t< std::is_const_v< TValue >, const object_value_type &, object_value_type & > pair) noexcept
 Refer to the key and value of pair.
 
template<typename UValue , typename = std::enable_if_t< !std::is_same_v<UValue, TValue> && std::is_convertible_v<UValue&, TValue&> >>
 basic_object_reference (const basic_object_reference< UValue > &source) noexcept
 This allows conversion from an object_reference to a const_object_reference.
 
template<typename TPair , typename = std::enable_if_t<std::is_same_v<TPair, object_value_type>>>
 operator TPair () const
 Copy the member into an object_value_type.
 

Public Attributes

const std::string & first
 The key of the member.
 
TValue & second
 The value of the member.
 

Detailed Description

template<typename TValue>
struct jsonv::value::basic_object_reference< TValue >

What dereferencing an object_iterator (TValue of value) or a const_object_iterator (TValue of const value) gives: references to the key and value of one member.

Like the reference of std::flat_map, it is a proxy returned by value, so auto& m : obj.as_object() does not compile – write auto&& m, const auto& m or auto&& [key, val]. The key is always const, since changing it would break the order members are kept in.

The conversion to object_value_type is explicit because it copies the value. A loop written as const value::object_value_type& m : obj.as_object() – which before members were stored contiguously bound straight to the member – would otherwise still compile and deep-copy every one of them.

Definition at line 345 of file value.hpp.

Member Typedef Documentation

◆ first_type

template<typename TValue >
using jsonv::value::basic_object_reference< TValue >::first_type = const std::string

The type of first, as in std::pair, which this stands in for.

Definition at line 349 of file value.hpp.

◆ second_type

template<typename TValue >
using jsonv::value::basic_object_reference< TValue >::second_type = TValue

The type of second, as in std::pair.

Definition at line 352 of file value.hpp.

Constructor & Destructor Documentation

◆ basic_object_reference() [1/3]

template<typename TValue >
jsonv::value::basic_object_reference< TValue >::basic_object_reference ( const std::string &  key,
TValue &  val 
)
inlinenoexcept

Refer to key and val.

Definition at line 363 of file value.hpp.

◆ basic_object_reference() [2/3]

template<typename TValue >
jsonv::value::basic_object_reference< TValue >::basic_object_reference ( std::conditional_t< std::is_const_v< TValue >, const object_value_type &, object_value_type & >  pair)
inlinenoexcept

Refer to the key and value of pair.

Definition at line 369 of file value.hpp.

◆ basic_object_reference() [3/3]

template<typename TValue >
template<typename UValue , typename = std::enable_if_t< !std::is_same_v<UValue, TValue> && std::is_convertible_v<UValue&, TValue&> >>
jsonv::value::basic_object_reference< TValue >::basic_object_reference ( const basic_object_reference< UValue > &  source)
inlinenoexcept

This allows conversion from an object_reference to a const_object_reference.

Definition at line 382 of file value.hpp.

Member Function Documentation

◆ operator TPair()

template<typename TValue >
template<typename TPair , typename = std::enable_if_t<std::is_same_v<TPair, object_value_type>>>
jsonv::value::basic_object_reference< TValue >::operator TPair ( ) const
inlineexplicit

Copy the member into an object_value_type.

Template Parameters
TPairAlways object_value_type. It is a parameter so that nothing names that pair until the conversion is used: MSVC instantiates a type a template's body names when it reads the body, and here that is before value is complete.

Definition at line 394 of file value.hpp.

Member Data Documentation

◆ first

template<typename TValue >
const std::string& jsonv::value::basic_object_reference< TValue >::first

The key of the member.

Definition at line 356 of file value.hpp.

◆ second

template<typename TValue >
TValue& jsonv::value::basic_object_reference< TValue >::second

The value of the member.

Definition at line 359 of file value.hpp.


The documentation for this struct was generated from the following file: