Crow  1.1
A C++ microframework for the web
 
Loading...
Searching...
No Matches
crow::ordered_object< Key, Value > Class Template Reference

An object-like container with unique keys stored in insertion order. New keys are added at the end; existing keys retain their position. More...

#include <utility.h>

Public Types

using key_type = Key
 
using value_type = std::pair< key_type, Value >
 
using storage_type = std::vector< value_type >
 
using iterator = typename storage_type::iterator
 
using const_iterator = typename storage_type::const_iterator
 

Public Member Functions

 ordered_object (const ordered_object &)=default
 
 ordered_object (ordered_object &&) noexcept=default
 
ordered_object & operator= (const ordered_object &other)
 
ordered_object & operator= (ordered_object &&) noexcept=default
 
 ordered_object (std::initializer_list< std::pair< const key_type, Value > > initializer_list)
 
ordered_object & operator= (std::initializer_list< std::pair< const key_type, Value > > initializer_list)
 
Value & operator[] (const key_type &key)
 Return the value for a key, adding a new key at the end if it does not exist. Updating an existing key does not change its position.
 
iterator find (const key_type &key)
 
const_iterator find (const key_type &key) const
 
std::size_t count (const key_type &key) const
 Return the count of a key, which is either zero or one.
 
bool contains (const key_type &key) const
 
iterator begin ()
 Return an iterator to the first entry in insertion order.
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
template<typename K , typename V >
std::pair< iterator, bool > emplace (K &&key, V &&value)
 Insert a key-value pair at the end if the key is not already present. Existing keys are ignored.
 
template<typename InputIt >
void insert (InputIt first, InputIt last)
 Insert new keys from a range in input order; existing keys are ignored.
 
void clear ()
 
std::size_t size () const
 

Detailed Description

template<typename Key, typename Value>
class crow::ordered_object< Key, Value >

An object-like container with unique keys stored in insertion order. New keys are added at the end; existing keys retain their position.

Template Parameters
Keythe key type
Valuethe mapped value type

Member Function Documentation

◆ begin()

template<typename Key , typename Value >
iterator crow::ordered_object< Key, Value >::begin ( )
inline

Return an iterator to the first entry in insertion order.

Returns
an iterator to the first entry

◆ count()

template<typename Key , typename Value >
std::size_t crow::ordered_object< Key, Value >::count ( const key_type &  key) const
inline

Return the count of a key, which is either zero or one.

Parameters
keythe key to count
Returns
1 if the key exists, otherwise 0

◆ emplace()

template<typename Key , typename Value >
template<typename K , typename V >
std::pair< iterator, bool > crow::ordered_object< Key, Value >::emplace ( K &&  key,
V &&  value 
)
inline

Insert a key-value pair at the end if the key is not already present. Existing keys are ignored.

Template Parameters
Kthe key type
Vthe mapped value type
Parameters
keythe key to insert
valuethe value to insert
Returns
an iterator to the entry and whether insertion took place

◆ insert()

template<typename Key , typename Value >
template<typename InputIt >
void crow::ordered_object< Key, Value >::insert ( InputIt  first,
InputIt  last 
)
inline

Insert new keys from a range in input order; existing keys are ignored.

Template Parameters
InputItthe input iterator type
Parameters
firstthe beginning of the range
lastthe end of the range
Returns
nothing

◆ operator[]()

template<typename Key , typename Value >
Value & crow::ordered_object< Key, Value >::operator[] ( const key_type &  key)
inline

Return the value for a key, adding a new key at the end if it does not exist. Updating an existing key does not change its position.

Parameters
keythe key to look up
Returns
the value associated with the key

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