mixin.h
Go to the documentation of this file.
// -*- C++ -*- (c) 2007 Peter Rockai <me@mornfall.net>
#ifndef WIBBLE_MIXIN_H
#define WIBBLE_MIXIN_H
#include <cstddef>
#include <iterator>
namespace wibble {
namespace mixin {
template< typename Self >
struct Comparable {
const Self &cmpSelf() const {
return *static_cast< const Self * >( this );
}
bool operator!=( const Self &o ) const {
return not( cmpSelf() == o );
}
bool operator==( const Self &o ) const {
return cmpSelf() <= o && o <= cmpSelf();
}
bool operator<( const Self &o ) const {
return cmpSelf() <= o && cmpSelf() != o;
}
bool operator>( const Self &o ) const {
return o <= cmpSelf() && cmpSelf() != o;
}
bool operator>=( const Self &o ) const {
return o <= cmpSelf();
}
// you implement this one in your class
// bool operator<=( const Self &o ) const { return this <= &o; }
};
template< typename Self >
struct OutputIterator :
public std::iterator<std::output_iterator_tag, void, void, void, void>
{
Self& operator++() {
return *static_cast<Self*>(this);
}
Self operator++(int)
{
Self res = *static_cast<Self*>(this);
++*this;
return res;
}
Self& operator*() {
return *static_cast<Self*>(this);
}
};
}
}
#endif
wibble
Definition: amorph.h:17
wibble::iterator
Iterator< typename I::value_type > iterator(I i)
Definition: iterator.h:123
wibble::mixin::Comparable
Definition: mixin.h:13
wibble::mixin::Comparable::operator>=
bool operator>=(const Self &o) const
Definition: mixin.h:35
wibble::mixin::Comparable::operator>
bool operator>(const Self &o) const
Definition: mixin.h:31
wibble::mixin::Comparable::cmpSelf
const Self & cmpSelf() const
Definition: mixin.h:15
wibble::mixin::Comparable::operator==
bool operator==(const Self &o) const
Definition: mixin.h:23
wibble::mixin::Comparable::operator<
bool operator<(const Self &o) const
Definition: mixin.h:27
wibble::mixin::Comparable::operator!=
bool operator!=(const Self &o) const
Definition: mixin.h:19
wibble::mixin::OutputIterator
Mixin with output iterator paperwork.
Definition: mixin.h:52
wibble::mixin::OutputIterator::operator++
Self operator++(int)
Definition: mixin.h:57
wibble::mixin::OutputIterator::operator*
Self & operator*()
Definition: mixin.h:64
wibble::mixin::OutputIterator::operator++
Self & operator++()
Definition: mixin.h:53