9#include "helpers/formatstring.h"
30 std::cout << std::endl;
31 std::cout <<
"Iterator Exercise" << std::endl;
37 std::cout <<
" Iterating over keys only:" << std::endl;
38 auto keyIterator = items.
GetKeys();
40 while (keyIterator->Next(item))
45 std::cout <<
" Iterating over values only:" << std::endl;
48 while (valueIterator->Next(value))
53 std::cout <<
" Iterating over all items:" << std::endl;
54 auto itemIterator = items.
GetItems();
56 while (itemIterator->Next(key_value_pair))
59 key_value_pair.
Key.c_str(), key_value_pair.
Value.c_str())
63 std::cout <<
" Done." << std::endl;
Declaration of the IteratorContainer_Class class, the IIterator interface, along with the implementat...
Represents a key/value pair where the key and value are strings.
Represents a container that offers up two kinds of iterators for the hardcoded contents,...
std::shared_ptr< IIterator< std::string > > GetKeys()
Retrieve an iterator over the "key" part of the data, where the data returned from the iterator is a ...
std::shared_ptr< IIterator< ItemPair > > GetItems()
Retrieve an iterator over the data that returns an ItemPair object containing both key and value for ...
std::shared_ptr< IIterator< std::string > > GetValues()
Retrieve an iterator over the "value" part of the data, where the data returned from the iterator is ...
Declaration of the Iterator_Exercise() function as used in the Iterator Pattern.
The namespace containing all Design Pattern Examples implemented in C++.
void Iterator_Exercise()
Example of using the Iterator design pattern.
std::string formatstring(const char *fmt,...)
Use the given string and arguments to return a buffer containing the formatted string....