Template Class OrderedDict#
Defined inFile ordered_dict.h
Nested Relationships#
Nested Types#
Class Documentation#
- template<typenameKey,typenameValue>
classOrderedDict# An ordered dictionary implementation, akin to Python’s
OrderedDict.Public Types
Public Functions
- explicitOrderedDict(std::stringkey_description="Key")#
Constructs the
OrderedDictwith a short description of the kinds of keys stored in theOrderedDict.This description is used in error messages thrown by the
OrderedDict.
- OrderedDict(constOrderedDict&other)#
Copy constructs this
OrderedDictfromother.
- OrderedDict&operator=(constOrderedDict&other)#
Assigns items from
otherto thisOrderedDict.
- OrderedDict(OrderedDict&&other)noexcept=default#
- OrderedDict&operator=(OrderedDict&&other)noexcept=default#
- ~OrderedDict()=default#
- OrderedDict(std::initializer_list<Item>initializer_list)#
Constructs a new
OrderedDictand pre-populates it with the givenItems.
- conststd::string&key_description()constnoexcept#
Returns the key description string the
OrderedDictwas constructed with.
- Item&front()#
Returns the very first item in the
OrderedDictand throws an exception if it is empty.
- constItem&front()const#
Returns the very first item in the
OrderedDictand throws an exception if it is empty.
- Item&back()#
Returns the very last item in the
OrderedDictand throws an exception if it is empty.
- constItem&back()const#
Returns the very last item in the
OrderedDictand throws an exception if it is empty.
- Item&operator[](size_tindex)#
Returns the item at the
index-th position in theOrderedDict.Throws an exception if the index is out of bounds.
- constItem&operator[](size_tindex)const#
Returns the item at the
index-th position in theOrderedDict.Throws an exception if the index is out of bounds.
- Value&operator[](constKey&key)#
Returns the value associated with the given
key.Throws an exception if no such key is stored in the
OrderedDict. Usefind()for a non-throwing way of accessing a value if it is present.
- constValue&operator[](constKey&key)const#
Returns the value associated with the given
key.Throws an exception if no such key is stored in the
OrderedDict. Usefind()for a non-throwing way of accessing a value if it is present.
- Value*find(constKey&key)noexcept#
Returns a pointer to the value associated with the given key, or a
nullptrif no such key is stored in theOrderedDict.
- constValue*find(constKey&key)constnoexcept#
Returns a pointer to the value associated with the given key, or a
nullptrif no such key is stored in theOrderedDict.
- boolcontains(constKey&key)constnoexcept#
Returns true if the key is present in the
OrderedDict.
- Iteratorbegin()#
Returns an iterator to the first item in the
OrderedDict.Iteration is ordered.
- ConstIteratorbegin()const#
Returns an iterator to the first item in the
OrderedDict.Iteration is ordered.
- Iteratorend()#
Returns an iterator one past the last item in the
OrderedDict.
- ConstIteratorend()const#
Returns an iterator one past the last item in the
OrderedDict.
- size_tsize()constnoexcept#
Returns the number of items currently stored in the
OrderedDict.
- boolis_empty()constnoexcept#
Returns true if the
OrderedDictcontains no elements.
- voidreserve(size_trequested_capacity)#
Resizes internal storage to fit at least
requested_capacityitems without requiring reallocation.
- template<typenameK,typenameV>
Value&insert(K&&key,V&&value)# Inserts a new
(key,value)pair into theOrderedDict.Throws an exception if the key is already present. If insertion is successful, immediately returns a reference to the inserted value.
- Value&insert(Keykey,Value&&value)#
Inserts a new
(key,value)pair into theOrderedDict.Throws an exception if the key is already present. If insertion is successful, immediately returns a reference to the inserted value.
- voidupdate(OrderedDict&&other)#
Inserts all items from
otherinto thisOrderedDict.If any key from
otheris already present in thisOrderedDict, an exception is thrown.
- voidupdate(constOrderedDict&other)#
Inserts all items from
otherinto thisOrderedDict.If any key from
otheris already present in thisOrderedDict, an exception is thrown.
- voiderase(constKey&key)#
Removes the item that has
keyfrom thisOrderedDictif exists and if it doesn’t an exception is thrown.
- voidclear()#
Removes all items from this
OrderedDict.
- conststd::vector<Item>&items()constnoexcept#
Returns the items stored in the
OrderedDict.
- ::std::vector<Key>keys()const#
Returns a newly allocated vector and copies all keys from this
OrderedDictinto the vector.
- ::std::vector<Value>values()const#
Returns a newly allocated vector and copies all values from this
OrderedDictinto the vector.
- ::std::vector<std::pair<Key,Value>>pairs()const#
Returns a newly allocated vector and copies all keys and values from this
OrderedDictinto a vector ofstd::pair<Key,Value>.
Friends
- template<typenameK,typenameV>
friendbooloperator==(constOrderedDict<K,V>&a,constOrderedDict<K,V>&b)# Returns true if both dicts contain the same keys and values, in the same order.
- classItem#
Public Functions
- explicitOrderedDict(std::stringkey_description="Key")#