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 <bits/stl_iterator_base_types.h> 00027 00028 #include <cstddef> 00029 #include <bits/stl_iterator_base_types.h> 00030 00031 namespace wibble { 00032 00033 template<typename T> 00034 class Empty 00035 { 00036 public: 00037 typedef T value_type; 00038 00039 class const_iterator : public std::iterator<std::forward_iterator_tag, const T, void, const T*, const T&> 00040 { 00041 public: 00042 const T& operator*() const { return *(T*)0; } 00043 const T* operator->() const { return 0; } 00044 const_iterator& operator++() { return *this; } 00045 bool operator==(const const_iterator&) const { return true; } 00046 bool operator!=(const const_iterator&) const { return false; } 00047 }; 00048 00049 class iterator : public std::iterator<std::forward_iterator_tag, T, void, T*, T&> 00050 { 00051 public: 00052 T& operator*() const { return *(T*)0; } 00053 T* operator->() const { return 0; } 00054 iterator& operator++() { return *this; } 00055 bool operator==(const iterator&) const { return true; } 00056 bool operator!=(const iterator&) const { return false; } 00057 }; 00058 00059 bool empty() const { return true; } 00060 size_t size() const { return 0; } 00061 00062 iterator begin() { return iterator(); } 00063 iterator end() { return iterator(); } 00064 const_iterator begin() const { return const_iterator(); } 00065 const_iterator end() const { return const_iterator(); } 00066 }; 00067 00068 } 00069 00070 // vim:set ts=4 sw=4: 00071 #endif