wibble 1.1
empty.h
Go to the documentation of this file.
1// -*- C++ -*-
2#ifndef WIBBLE_EMPTY_H
3#define WIBBLE_EMPTY_H
4
5/*
6 * Degenerated container to hold a single value
7 *
8 * Copyright (C) 2006 Enrico Zini <enrico@debian.org>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#include <cstddef>
26#include <iterator>
27
28namespace wibble {
29
30template<typename T>
31class Empty
32{
33public:
34 typedef T value_type;
35
36 class const_iterator : public std::iterator<std::forward_iterator_tag, const T, void, const T*, const T&>
37 {
38 public:
39 const T& operator*() const { return *reinterpret_cast< T* >( 0 ); }
40 const T* operator->() const { return 0; }
41 const_iterator& operator++() { return *this; }
42 bool operator==(const const_iterator&) const { return true; }
43 bool operator!=(const const_iterator&) const { return false; }
44 };
45
46 class iterator : public std::iterator<std::forward_iterator_tag, T, void, T*, T&>
47 {
48 public:
49 T& operator*() const { return *reinterpret_cast< T* >( 0 ); }
50 T* operator->() const { return 0; }
51 iterator& operator++() { return *this; }
52 bool operator==(const iterator&) const { return true; }
53 bool operator!=(const iterator&) const { return false; }
54 };
55
56 bool empty() const { return true; }
57 size_t size() const { return 0; }
58
59 iterator begin() { return iterator(); }
60 iterator end() { return iterator(); }
61 const_iterator begin() const { return const_iterator(); }
62 const_iterator end() const { return const_iterator(); }
63};
64
65}
66
67// vim:set ts=4 sw=4:
68#endif
Definition empty.h:37
const T * operator->() const
Definition empty.h:40
const T & operator*() const
Definition empty.h:39
bool operator==(const const_iterator &) const
Definition empty.h:42
bool operator!=(const const_iterator &) const
Definition empty.h:43
const_iterator & operator++()
Definition empty.h:41
Definition empty.h:47
bool operator==(const iterator &) const
Definition empty.h:52
T * operator->() const
Definition empty.h:50
iterator & operator++()
Definition empty.h:51
T & operator*() const
Definition empty.h:49
bool operator!=(const iterator &) const
Definition empty.h:53
Definition empty.h:32
const_iterator begin() const
Definition empty.h:61
T value_type
Definition empty.h:34
iterator end()
Definition empty.h:60
size_t size() const
Definition empty.h:57
const_iterator end() const
Definition empty.h:62
iterator begin()
Definition empty.h:59
bool empty() const
Definition empty.h:56
Definition amorph.h:17