|
Boost : |
From: Thomas Witt (witt_at_[hidden])
Date: 2002-02-20 05:42:00
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
The problem:
- -------------
Creating iterators and function objects that select certain fields of a tuple.
This is a common problem when working with maps. Think iterating over key or
data values. Think sgi::select1st. Unfortunately std::pair is not a tuple and
sgi::selectXX does not scale.
Therefore I propose the following extension to tuple:
- -----------------------------------------------------
The basic idea is define a tuple concept and make std::pair model that
concept.
What is needed (pseudo code):
- -----------------------------
* Additional overloads for get functions so that pair elements can be accessed
std::pair<int, int> pr(1, 1);
boost::get<0>(pr) == pr.first;
* Tuple traits so that tuple properties can be queried
template<class T>
struct tuple_traits
{
.....
template <int N>
struct element
{
typedef ..... type;
};
};
This will give us:
- ------------------
* Select iterator adaptors that work for tuple and pairs. Select iterators
are read/write depending on base iterator :
std::map<int, std::string> data;
data[0] = "Null";
data[1] = "One";
data[2] = "Two";
data[3] = "Three";
std::copy(make_select_iterator<1>(data.begin()),
make_select_iterator<1>(data.end()),
std::ostream_iterator<std::string>(std::cout, " "));
// Produces "Null One Two Three"
* A more general replacement for sgi::selectXXX
typedef boost::tuple<double, double, int> tTuple;
std::vector< tTuple > tpl;
transform(tpl.begin(), tpl.end(), ostream_iterator<int>(cout, " "),
select<2, tTuple>());
- ---
This is not just a pipe dream. A working prototype for select iterators is
available and works for g++/intel/metrowerks.
Any comments would be appreciated
Regards
Thomas
- --
Dipl.-Ing. Thomas Witt
Institut fuer Verkehrswesen, Eisenbahnbau und -betrieb, Universitaet Hannover
voice: +49(0) 511 762 - 4273, fax: +49(0) 511 762-3001
http://www.ive.uni-hannover.de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE8c31+0ds/gS3XsBoRAtQ0AJ4vDPIxPFmH5fXP3c9o7DmwjceAKACfft1n
HuFGTps+sLHgDMaGDtscf2k=
=/jdm
-----END PGP SIGNATURE-----
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk