wibble 0.1.28
|
00001 // -*- C++ -*- 00002 #ifndef WIBBLE_EMPTY_H 00003 #define WIBBLE_EMPTY_H 00004 00005 /* 00006 * Degenerated container to hold a single value 00007 * 00008 * Copyright (C) 2006 Enrico Zini <enrico@debian.org> 00009 * 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2.1 of the License, or (at your option) any later version. 00014 * 00015 * This library is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with this library; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 */ 00024 00025 #include <cstddef> 00026 #include <iterator> 00027 00028 namespace wibble { 00029 00030 template<typename T> 00031 class Empty 00032 { 00033 public: 00034 typedef T value_type; 00035 00036 class const_iterator : public std::iterator<std::forward_iterator_tag, const T, void, const T*, const T&> 00037 { 00038 public: 00039 const T& operator*() const { return *(T*)0; } 00040 const T* operator->() const { return 0; } 00041 const_iterator& operator++() { return *this; } 00042 bool operator==(const const_iterator&) const { return true; } 00043 bool operator!=(const const_iterator&) const { return false; } 00044 }; 00045 00046 class iterator : public std::iterator<std::forward_iterator_tag, T, void, T*, T&> 00047 { 00048 public: 00049 T& operator*() const { return *(T*)0; } 00050 T* operator->() const { return 0; } 00051 iterator& operator++() { return *this; } 00052 bool operator==(const iterator&) const { return true; } 00053 bool operator!=(const iterator&) const { return false; } 00054 }; 00055 00056 bool empty() const { return true; } 00057 size_t size() const { return 0; } 00058 00059 iterator begin() { return iterator(); } 00060 iterator end() { return iterator(); } 00061 const_iterator begin() const { return const_iterator(); } 00062 const_iterator end() const { return const_iterator(); } 00063 }; 00064 00065 } 00066 00067 // vim:set ts=4 sw=4: 00068 #endif