File: empty.h

package info (click to toggle)
libwibble 0.1.9
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 500 kB
  • ctags: 1,183
  • sloc: cpp: 5,760; sh: 113; makefile: 71
file content (68 lines) | stat: -rw-r--r-- 2,104 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// -*- C++ -*-
#ifndef WIBBLE_EMPTY_H
#define WIBBLE_EMPTY_H

/*
 * Degenerated container to hold a single value
 *
 * Copyright (C) 2006  Enrico Zini <enrico@debian.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 */

#include <cstddef>
#include <bits/stl_iterator_base_types.h>

namespace wibble {

template<typename T>
class Empty
{
public:
	typedef T value_type;

	class const_iterator : public std::iterator<std::forward_iterator_tag, const T, void, const T*, const T&>
	{
	public:
		const T& operator*() const { return *(T*)0; }
		const T* operator->() const { return 0; }
		const_iterator& operator++() { return *this; }
		bool operator==(const const_iterator&) const { return true; }
		bool operator!=(const const_iterator&) const { return false; }
	};
	
	class iterator : public std::iterator<std::forward_iterator_tag, T, void, T*, T&>
	{
	public:
		T& operator*() const { return *(T*)0; }
		T* operator->() const { return 0; }
		iterator& operator++() { return *this; }
		bool operator==(const iterator&) const { return true; }
		bool operator!=(const iterator&) const { return false; }
	};
	
	bool empty() const { return true; }
	size_t size() const { return 0; }

	iterator begin() { return iterator(); }
	iterator end() { return iterator(); }
	const_iterator begin() const { return const_iterator(); }
	const_iterator end() const { return const_iterator(); }
};

}

// vim:set ts=4 sw=4:
#endif