#ifndef MULTIABLE_SET__H
#define MULTIABLE_SET__H

#include <set>
#include <functional>
#include "if.h"

template <class T, bool ismulti, class Compare = std::less<T> >
class MultiableSet
{
  std::multiset<T, Compare> m;
public:

  int size() const
  {
    return m.size();
  }

  MultiableSet<T, ismulti, Compare>& insert(const T& t)
  {
    if (ismulti || 0 == m.count(t))
      m.insert(t);
    return *this;
  }

  int erase(const T& t)
  {
    return m.erase(t);
  }

  int count(const T& t) const
  {
    return m.count(t);
  }

  Compare key_comp() const
  {
    return m.key_comp();
  }

  template <class InputIterator>
  void insert(InputIterator first, InputIterator last)
  {
    while (first != last)
      insert(*first++);
  }

  typename If<ismulti, std::multiset<T, Compare>, std::set<T, Compare> >::Ret
    data() const
  {
    return typename If<ismulti, std::multiset<T, Compare>, std::set<T, Compare> >::Ret(m.begin(), m.end());
  }
};

#endif

