A key/value pair. This is the type of element used by the @ref object container. */
| 3338 | This is the type of element used by the @ref object container. |
| 3339 | */ |
| 3340 | class key_value_pair |
| 3341 | { |
| 3342 | #ifndef BOOST_JSON_DOCS |
| 3343 | friend struct detail::access; |
| 3344 | using access = detail::access; |
| 3345 | #endif |
| 3346 | |
| 3347 | BOOST_JSON_DECL |
| 3348 | static char const empty_[1]; |
| 3349 | |
| 3350 | inline |
| 3351 | key_value_pair( |
| 3352 | pilfered<json::value> k, |
| 3353 | pilfered<json::value> v) noexcept; |
| 3354 | |
| 3355 | public: |
| 3356 | /** Assignment |
| 3357 | |
| 3358 | This type is not copy or move-assignable. The copy assignment operator |
| 3359 | is deleted. |
| 3360 | */ |
| 3361 | key_value_pair& |
| 3362 | operator=(key_value_pair const&) = delete; |
| 3363 | |
| 3364 | /** Destructor. |
| 3365 | |
| 3366 | The value is destroyed and all internally allocated memory is freed. |
| 3367 | */ |
| 3368 | ~key_value_pair() noexcept |
| 3369 | { |
| 3370 | auto const& sp = value_.storage(); |
| 3371 | if(sp.is_not_shared_and_deallocate_is_trivial()) |
| 3372 | return; |
| 3373 | if(key_ == empty_) |
| 3374 | return; |
| 3375 | sp->deallocate(const_cast<char*>(key_), |
| 3376 | len_ + 1, alignof(char)); |
| 3377 | } |
| 3378 | |
| 3379 | /** Constructors. |
| 3380 | |
| 3381 | Construct a key/value pair. |
| 3382 | |
| 3383 | @li **(1)** uses a copy of the characters of `key`, and constructs the |
| 3384 | value as if by `value(std::forward<Args>(args)...)`. |
| 3385 | @li **(2)** equivalent to `key_value_pair(p.first, p.second, sp)`. |
| 3386 | @li **(3)** equivalent to |
| 3387 | `key_value_pair(p.first, std::move(p.second), sp)`. |
| 3388 | @li **(4)** equivalent to |
| 3389 | `key_value_pair(other.key(), other.value(), sp)`. |
| 3390 | @li **(5)** equivalent to |
| 3391 | `key_value_pair(other.key(), other.value(), other.storage())`. |
| 3392 | @li **(6)** the pair s constructed by acquiring ownership of the |
| 3393 | contents of `other` using move semantics. |
| 3394 | @li **(7)** the pair is constructed by acquiring ownership of the |
| 3395 | contents of `other` using pilfer semantics. This is more efficient |
| 3396 | than move construction, when it is known that the moved-from object |
| 3397 | will be immediately destroyed afterwards. |