8#ifndef Sawyer_DistinctList_H 
    9#define Sawyer_DistinctList_H 
   11#include <boost/foreach.hpp> 
   13#include <Sawyer/Map.h> 
   14#include <Sawyer/Sawyer.h> 
   23template<
class T, 
class Cmp = std::less<T> >
 
   27    typedef Cmp Comparator;
 
   28    typedef std::list<Item> Items;                      
 
   40    template<
class T2, 
class Cmp2>
 
   42        BOOST_FOREACH (
const T2 &item, other.
items())
 
 
   47    template<
class T2, 
class Cmp2>
 
   50        BOOST_FOREACH (
const T2 &item, other.
items())
 
 
   74        return position_.
size();
 
 
   80    bool exists(
const Item &item)
 const {
 
   81        return position_.
exists(item);
 
 
   88        if (!position_.
exists(item))
 
   91        BOOST_FOREACH (
const Item &x, items_) {
 
 
  105            throw std::runtime_error(
"front called on empty list");
 
  106        return items_.front();
 
 
  115            throw std::runtime_error(
"back called on empty list");
 
  116        return items_.back();
 
 
  124        if (found == position_.
nodes().end()) {
 
  125            items_.push_front(item);
 
  126            position_.
insert(item, items_.begin());
 
 
  135        if (found == position_.
nodes().end()) {
 
  136            items_.push_back(item);
 
  137            position_.
insert(item, --items_.end());
 
 
  147            throw std::runtime_error(
"popFront called on empty list");
 
  148        Item item = items_.front();
 
  150        position_.
erase(item);
 
 
  160            throw std::runtime_error(
"popBack called on empty list");
 
  161        Item item = items_.back();
 
  163        position_.
erase(item);
 
 
  172        if (found != position_.
nodes().end()) {
 
  173            items_.erase(found->
value());
 
 
 
A doubly-linked list of distinct items.
 
size_t position(const Item &item) const
Determine the position of an item.
 
DistinctList & operator=(const DistinctList< T2, Cmp2 > &other)
Assign one list to another.
 
void clear()
Clear the list.
 
DistinctList(const DistinctList< T2, Cmp2 > &other)
Copy-construct a list.
 
const Items & items() const
Return all items as a list.
 
void pushBack(const Item &item)
Insert item at back of list if distinct.
 
Item popFront()
Return and erase item at front of list.
 
size_t size() const
Number of items in list.
 
DistinctList()
Construct an empty list.
 
bool exists(const Item &item) const
Determine if an item exists.
 
bool isEmpty() const
Determines whether list is empty.
 
const Item & back() const
Reference to item at back of list.
 
Item popBack()
Return and erase item at back of list.
 
void pushFront(const Item &item)
Insert item at front of list if distinct.
 
void erase(const Item &item)
Erase an item from the list.
 
const Item & front() const
Reference to item at front of list.
 
Bidirectional iterator over key/value nodes.
 
Value & value()
Value part of key/value node.
 
Container associating values with keys.
 
NodeIterator find(const Key &key)
Find a node by key.
 
Map & eraseAt(const NodeIterator &iter)
Remove a node by iterator.
 
bool exists(const Key &key) const
Determine if a key exists.
 
size_t size() const
Number of nodes, keys, or values in this container.
 
bool isEmpty() const
Determines whether this container is empty.
 
Map & erase(const Key &key)
Remove a node with specified key.
 
boost::iterator_range< NodeIterator > nodes()
Iterators for container nodes.
 
Map & insert(const Key &key, const Value &value)
Insert or update a key/value pair.
 
Map & clear()
Remove all nodes.