00001
00002
00003 #ifndef WIBBLE_MIXIN_H
00004 #define WIBBLE_MIXIN_H
00005
00006 #include <cstddef>
00007 #include <bits/stl_iterator_base_types.h>
00008
00009 namespace wibble {
00010 namespace mixin {
00011
00012 template< typename Self >
00013 struct Comparable {
00014
00015 const Self &cmpSelf() const {
00016 return *static_cast< const Self * >( this );
00017 }
00018
00019 bool operator!=( const Self &o ) const {
00020 return not( cmpSelf() == o );
00021 }
00022
00023 bool operator==( const Self &o ) const {
00024 return cmpSelf() <= o && o <= cmpSelf();
00025 }
00026
00027 bool operator<( const Self &o ) const {
00028 return cmpSelf() <= o && cmpSelf() != o;
00029 }
00030
00031 bool operator>( const Self &o ) const {
00032 return o <= cmpSelf() && cmpSelf() != o;
00033 }
00034
00035 bool operator>=( const Self &o ) const {
00036 return o <= cmpSelf();
00037 }
00038
00039
00040
00041 };
00042
00049 template< typename Self >
00050 struct OutputIterator :
00051 public std::iterator<std::output_iterator_tag, void, void, void, void>
00052 {
00053 Self& operator++() {
00054 return *static_cast<Self*>(this);
00055 }
00056
00057 Self operator++(int)
00058 {
00059 Self res = *static_cast<Self*>(this);
00060 ++*this;
00061 return res;
00062 }
00063
00064 Self& operator*() {
00065 return *static_cast<Self*>(this);
00066 }
00067 };
00068
00069 }
00070 }
00071
00072 #endif