wibble
1.1
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
wibble::iterator
Iterator< typename I::value_type > iterator(I i)
Definition:
iterator.h:123
wibble::mixin::Comparable::operator<
bool operator<(const Self &o) const
Definition:
mixin.h:27
wibble::mixin::OutputIterator::operator++
Self operator++(int)
Definition:
mixin.h:57
wibble::mixin::Comparable::operator==
bool operator==(const Self &o) const
Definition:
mixin.h:23
wibble::mixin::OutputIterator::operator++
Self & operator++()
Definition:
mixin.h:53
wibble::mixin::Comparable
Definition:
mixin.h:13
wibble::mixin::Comparable::operator>
bool operator>(const Self &o) const
Definition:
mixin.h:31
wibble::mixin::OutputIterator::operator*
Self & operator*()
Definition:
mixin.h:64
wibble::mixin::Comparable::operator>=
bool operator>=(const Self &o) const
Definition:
mixin.h:35
wibble
Definition:
amorph.h:17
wibble::mixin::Comparable::operator!=
bool operator!=(const Self &o) const
Definition:
mixin.h:19
wibble::mixin::Comparable::cmpSelf
const Self & cmpSelf() const
Definition:
mixin.h:15
wibble::mixin::OutputIterator
Mixin with output iterator paperwork.
Definition:
mixin.h:50
Generated by
1.8.17