wibble 1.1
mixin.h
Go to the documentation of this file.
1// -*- C++ -*- (c) 2007 Peter Rockai <me@mornfall.net>
2
3#ifndef WIBBLE_MIXIN_H
4#define WIBBLE_MIXIN_H
5
6#include <cstddef>
7#include <iterator>
8
9namespace wibble {
10namespace mixin {
11
12template< typename Self >
13struct Comparable {
14
15 const Self &cmpSelf() const {
16 return *static_cast< const Self * >( this );
17 }
18
19 bool operator!=( const Self &o ) const {
20 return not( cmpSelf() == o );
21 }
22
23 bool operator==( const Self &o ) const {
24 return cmpSelf() <= o && o <= cmpSelf();
25 }
26
27 bool operator<( const Self &o ) const {
28 return cmpSelf() <= o && cmpSelf() != o;
29 }
30
31 bool operator>( const Self &o ) const {
32 return o <= cmpSelf() && cmpSelf() != o;
33 }
34
35 bool operator>=( const Self &o ) const {
36 return o <= cmpSelf();
37 }
38
39 // you implement this one in your class
40 // bool operator<=( const Self &o ) const { return this <= &o; }
41};
42
49template< typename Self >
51 public std::iterator<std::output_iterator_tag, void, void, void, void>
52{
54 return *static_cast<Self*>(this);
55 }
56
58 {
59 Self res = *static_cast<Self*>(this);
60 ++*this;
61 return res;
62 }
63
65 return *static_cast<Self*>(this);
66 }
67};
68
69}
70}
71
72#endif
Definition amorph.h:17
Definition amorph.h:30
Definition mixin.h:13
bool operator>=(const Self &o) const
Definition mixin.h:35
bool operator>(const Self &o) const
Definition mixin.h:31
bool operator==(const Self &o) const
Definition mixin.h:23
bool operator<(const Self &o) const
Definition mixin.h:27
bool operator!=(const Self &o) const
Definition mixin.h:19
const Self & cmpSelf() const
Definition mixin.h:15
Mixin with output iterator paperwork.
Definition mixin.h:52
Self operator++(int)
Definition mixin.h:57
Self & operator*()
Definition mixin.h:64
Self & operator++()
Definition mixin.h:53