wibble
1.1
Main Page
Namespaces
Classes
Files
File List
File Members
wibble
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
9
namespace
wibble {
10
namespace
mixin {
11
12
template
<
typename
Self >
13
struct
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
49
template
<
typename
Self >
50
struct
OutputIterator
:
51
public
std::iterator
<std::output_iterator_tag, void, void, void, void>
52
{
53
Self&
operator++
() {
54
return
*
static_cast<
Self*
>
(
this
);
55
}
56
57
Self
operator++
(
int
)
58
{
59
Self res = *
static_cast<
Self*
>
(
this
);
60
++*
this
;
61
return
res;
62
}
63
64
Self&
operator*
() {
65
return
*
static_cast<
Self*
>
(
this
);
66
}
67
};
68
69
}
70
}
71
72
#endif
Generated on Wed Oct 23 2013 17:14:25 for wibble by
1.8.4