- Add support for input sequences via template; this should simplify a little
iterating over containers git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@857 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
parent
b1327341af
commit
390af1f09d
|
@ -326,6 +326,7 @@ glade_DATA = \
|
||||||
pkginclude_HEADERS += \
|
pkginclude_HEADERS += \
|
||||||
src/templates/deletor.tcc \
|
src/templates/deletor.tcc \
|
||||||
src/templates/parameter.tcc \
|
src/templates/parameter.tcc \
|
||||||
|
src/templates/sequences.tcc \
|
||||||
src/templates/singleton.hh \
|
src/templates/singleton.hh \
|
||||||
src/templates/singleton.tcc \
|
src/templates/singleton.tcc \
|
||||||
src/templates/smartp.hh \
|
src/templates/smartp.hh \
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
// 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 <iterator>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
// Class defining an input sequence
|
||||||
|
|
||||||
|
template<typename In>
|
||||||
|
class Iseq : protected std::pair<In, In>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef typename In::pointer pointer;
|
||||||
|
typedef typename In::reference reference;
|
||||||
|
|
||||||
|
explicit Iseq(In a, In b)
|
||||||
|
: std::pair<In, In>(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; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Adaptor functions for containers:
|
||||||
|
|
||||||
|
template<class Container>
|
||||||
|
Iseq<typename Container::const_iterator>
|
||||||
|
iseq(const Container& c)
|
||||||
|
{
|
||||||
|
return Iseq<typename Container::const_iterator>(c.begin(), c.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Container>
|
||||||
|
Iseq<typename Container::iterator>
|
||||||
|
iseq(Container& c)
|
||||||
|
{
|
||||||
|
return Iseq<typename Container::iterator>(c.begin(), c.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Adaptor functions for containers that support reverse iteration
|
||||||
|
|
||||||
|
template<class Container>
|
||||||
|
Iseq<typename Container::const_reverse_iterator>
|
||||||
|
r_iseq(const Container& c)
|
||||||
|
{
|
||||||
|
return Iseq<typename Container::const_reverse_iterator>(c.rbegin(), c.rend());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class Container>
|
||||||
|
Iseq<typename Container::reverse_iterator>
|
||||||
|
r_iseq(Container& c)
|
||||||
|
{
|
||||||
|
return Iseq<typename Container::reverse_iterator>(c.rbegin(), c.rend());
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue