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 
28 namespace wibble {
29 
30 template<typename T>
31 class Empty
32 {
33 public:
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