empty.h
Go to the documentation of this file.
// -*- 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 <iterator>
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 *reinterpret_cast< 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 *reinterpret_cast< 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
wibble::iterator
Iterator< typename I::value_type > iterator(I i)
Definition: iterator.h:123
wibble::Empty::iterator::operator++
iterator & operator++()
Definition: empty.h:51
wibble::Empty::const_iterator
Definition: empty.h:36
wibble::Empty
Definition: empty.h:31
wibble::Empty::const_iterator::operator->
const T * operator->() const
Definition: empty.h:40
wibble::Empty::const_iterator::operator!=
bool operator!=(const const_iterator &) const
Definition: empty.h:43
wibble::Empty::begin
const_iterator begin() const
Definition: empty.h:61
wibble::Empty::iterator::operator->
T * operator->() const
Definition: empty.h:50
wibble::Empty::iterator::operator==
bool operator==(const iterator &) const
Definition: empty.h:52
wibble::Empty::value_type
T value_type
Definition: empty.h:34
wibble::Empty::const_iterator::operator==
bool operator==(const const_iterator &) const
Definition: empty.h:42
wibble::Empty::const_iterator::operator++
const_iterator & operator++()
Definition: empty.h:41
wibble::Empty::iterator::operator*
T & operator*() const
Definition: empty.h:49
wibble::Empty::iterator
Definition: empty.h:46
wibble::Empty::begin
iterator begin()
Definition: empty.h:59
wibble::Empty::end
iterator end()
Definition: empty.h:60
wibble::Empty::end
const_iterator end() const
Definition: empty.h:62
wibble::Empty::empty
bool empty() const
Definition: empty.h:56
wibble::Empty::const_iterator::operator*
const T & operator*() const
Definition: empty.h:39
wibble::Empty::iterator::operator!=
bool operator!=(const iterator &) const
Definition: empty.h:53
wibble
Definition: amorph.h:17
wibble::Empty::size
size_t size() const
Definition: empty.h:57