Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
sourcemeta::core::JSONObject< Key, Value, Hash >::Entry Struct Reference

A single object property entry. More...

Public Member Functions

auto key_equals (const KeyView key, const hash_type key_hash) const -> bool

Public Attributes

key_type first
 The property key.
mapped_type second
 The property value.
hash_type hash
 The precomputed hash of the property key.

Detailed Description

template<typename Key, typename Value, typename Hash>
struct sourcemeta::core::JSONObject< Key, Value, Hash >::Entry

A single object property entry.

Member Function Documentation

◆ key_equals()

template<typename Key, typename Value, typename Hash>
auto sourcemeta::core::JSONObject< Key, Value, Hash >::Entry::key_equals ( const KeyView key,
const hash_type key_hash ) const -> bool
inlinenodiscard

Check whether this entry's key equals the given key, comparing the precomputed hashes first and only falling back to a string comparison when the hash is not perfect. For example:

#include <sourcemeta/core/json.h>
#include <cassert>
const sourcemeta::core::JSON document =
sourcemeta::core::parse_json("{ \"foo\": 1 }");
const auto &entry{*document.as_object().cbegin()};
assert(entry.key_equals(
static constexpr auto hash(const String &key) noexcept -> hash_type
Definition json_object.h:181
SOURCEMETA_FORCEINLINE auto as_object() noexcept -> Object &
Definition json_value.h:791
Definition json_value.h:39
SOURCEMETA_CORE_JSON_EXPORT auto parse_json(std::basic_istream< JSON::Char, JSON::CharTraits > &stream) -> JSON

The documentation for this struct was generated from the following file:
  • /__w/core/core/src/core/json/include/sourcemeta/core/json_object.h