Boost logo

Boost :

From: Chris Hamilton (chamilton_at_[hidden])
Date: 2007-12-21 09:18:20


> I definitely think this would be useful, but more in the line of a
> general utility that allows me to create an input iterator that's
> based on a function object. Something like
> boost::make_function_output_iterator(...) only
> boost::make_function_input_iterator(...).
>
> I'm guessing, you might have a generic function that returns an
> iterator from a container. You might argue that it would be good to
> wrap your container in such a way that you have:
>
> std::list<std::string> cities; // contain the list of cities
> currently_unnamed_wrapper<unsigned int, std::list<std::string> >
> city_finder(cities);
> std::list<std::string>::iterator city_iterator = city_finder[zip_code];
> std::cout << *city_iterator << std::endl;
>
> Is this similar to what you've already implemented?

Not at all at this point. For simplicity, I defined an 'Indexer'
concept, which implements the following functions:

int lookup( const T& key ) const;
size_t size() const;
(plus some other callback type stuff to be discussed later)

These are passed to the 'LookupTable' class as template arguments, using
a trick similar to the 'tuple' class, and currently supporting up to 10
dimensions. The generated object then looks and feels like a
multi_array, but extended with 'operator()' which does lookups based on
key, rather than index. So, access to a two dimensional array with the
first dimension indexed using strings and the second using doubles would
be like:

a("string")(1.0)

I made the 'indexers' accessible through the LookupTable object through
a templated 'indexer<>' function. Since the indexers define the shape
of the array, it only makes sense that the shape be changed through
them. Thus, there's a callback mechanism (through friendly base
classes) that allows the indexer to inform the underlying array of any
shape changes (ie: remove indices n..n+k from dimension m, ...)

The whole function output iterator seems maybe 'too external', in that
it doesn't create a tight connection between the container indexing a
dimension and the underlying multi array; how to keep them in sync?

Chris


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk