// src/templates/sequences.tcc - Copyright 2005, 2006, University // of Padova, dept. of Pure and Applied // Mathematics // // This file is part of SGPEMv2. // // This is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // SGPEMv2 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 General Public License for more details. // // You should have received a copy of the GNU General Public License // along with SGPEMv2; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA /* Helper templates to make easier to work on an entire sequence over a container */ #include #include // Class defining an input sequence template class Iseq : protected std::pair { public: typedef typename In::pointer pointer; typedef typename In::reference reference; explicit Iseq(In a, In b) : std::pair(a, b) {} operator bool() { return Iseq::first != Iseq::second; } Iseq& operator++() { ++Iseq::first; return *this; } Iseq operator++(int) { Iseq t = *this; ++Iseq::first; return t; } const reference operator*() const { return *Iseq::first; } const In& operator->() const { return Iseq::first; } bool operator==(const Iseq& i) const { return Iseq::first == i.first; } bool operator!=(const Iseq& i) const { return Iseq::first != i.first; } }; // Adaptor functions for containers: template Iseq iseq(const Container& c) { return Iseq(c.begin(), c.end()); } template Iseq iseq(Container& c) { return Iseq(c.begin(), c.end()); } // Adaptor functions for containers that support reverse iteration template Iseq riseq(const Container& c) { return Iseq(c.rbegin(), c.rend()); } template Iseq riseq(Container& c) { return Iseq(c.rbegin(), c.rend()); }