Rate this Page

Template Class OrderedDict#

Nested Relationships#

Nested Types#

Class Documentation#

template<typenameKey,typenameValue>
classOrderedDict#

An ordered dictionary implementation, akin to Python’sOrderedDict.

Public Types

usingIterator=typenamestd::vector<Item>::iterator#
usingConstIterator=typenamestd::vector<Item>::const_iterator#

Public Functions

explicitOrderedDict(std::stringkey_description="Key")#

Constructs theOrderedDict with a short description of the kinds of keys stored in theOrderedDict.

This description is used in error messages thrown by theOrderedDict.

OrderedDict(constOrderedDict&other)#

Copy constructs thisOrderedDict fromother.

OrderedDict&operator=(constOrderedDict&other)#

Assigns items fromother to thisOrderedDict.

OrderedDict(OrderedDict&&other)noexcept=default#
OrderedDict&operator=(OrderedDict&&other)noexcept=default#
~OrderedDict()=default#
OrderedDict(std::initializer_list<Item>initializer_list)#

Constructs a newOrderedDict and pre-populates it with the givenItems.

conststd::string&key_description()constnoexcept#

Returns the key description string theOrderedDict was constructed with.

Item&front()#

Returns the very first item in theOrderedDict and throws an exception if it is empty.

constItem&front()const#

Returns the very first item in theOrderedDict and throws an exception if it is empty.

Item&back()#

Returns the very last item in theOrderedDict and throws an exception if it is empty.

constItem&back()const#

Returns the very last item in theOrderedDict and throws an exception if it is empty.

Item&operator[](size_tindex)#

Returns the item at theindex-th position in theOrderedDict.

Throws an exception if the index is out of bounds.

constItem&operator[](size_tindex)const#

Returns the item at theindex-th position in theOrderedDict.

Throws an exception if the index is out of bounds.

Value&operator[](constKey&key)#

Returns the value associated with the givenkey.

Throws an exception if no such key is stored in theOrderedDict. 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 givenkey.

Throws an exception if no such key is stored in theOrderedDict. 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 anullptr if no such key is stored in theOrderedDict.

constValue*find(constKey&key)constnoexcept#

Returns a pointer to the value associated with the given key, or anullptr if no such key is stored in theOrderedDict.

boolcontains(constKey&key)constnoexcept#

Returns true if the key is present in theOrderedDict.

Iteratorbegin()#

Returns an iterator to the first item in theOrderedDict.

Iteration is ordered.

ConstIteratorbegin()const#

Returns an iterator to the first item in theOrderedDict.

Iteration is ordered.

Iteratorend()#

Returns an iterator one past the last item in theOrderedDict.

ConstIteratorend()const#

Returns an iterator one past the last item in theOrderedDict.

size_tsize()constnoexcept#

Returns the number of items currently stored in theOrderedDict.

boolis_empty()constnoexcept#

Returns true if theOrderedDict contains no elements.

voidreserve(size_trequested_capacity)#

Resizes internal storage to fit at leastrequested_capacity items 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 fromother into thisOrderedDict.

If any key fromother is already present in thisOrderedDict, an exception is thrown.

voidupdate(constOrderedDict&other)#

Inserts all items fromother into thisOrderedDict.

If any key fromother is already present in thisOrderedDict, an exception is thrown.

voiderase(constKey&key)#

Removes the item that haskey from thisOrderedDict if exists and if it doesn’t an exception is thrown.

voidclear()#

Removes all items from thisOrderedDict.

conststd::vector<Item>&items()constnoexcept#

Returns the items stored in theOrderedDict.

::std::vector<Key>keys()const#

Returns a newly allocated vector and copies all keys from thisOrderedDict into the vector.

::std::vector<Value>values()const#

Returns a newly allocated vector and copies all values from thisOrderedDict into the vector.

::std::vector<std::pair<Key,Value>>pairs()const#

Returns a newly allocated vector and copies all keys and values from thisOrderedDict into 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

inlineItem(Keykey,Valuevalue)#

Constructs a new item.

inlineValue&operator*()#

Returns a reference to the value.

inlineconstValue&operator*()const#

Returns a reference to the value.

inlineValue*operator->()#

Allows access to the value using the arrow operator.

inlineconstValue*operator->()const#

Allows access to the value using the arrow operator.

inlineconstKey&key()constnoexcept#

Returns a reference to the key.

inlineValue&value()noexcept#

Returns a reference to the value.

inlineconstValue&value()constnoexcept#

Returns a reference to the value.

inlineconststd::pair<Key,Value>&pair()constnoexcept#

Returns a(key,value) pair.