/* 
   Mathieu Stefani, 28 février 2016
   
   A collection of sample iterator adapters
*/

#pragma once

template<typename Map>
struct FlatMapIteratorAdapter {
    typedef typename Map::key_type Key;
    typedef typename Map::mapped_type Value;
    typedef typename Map::const_iterator const_iterator;

    FlatMapIteratorAdapter(const_iterator it)
        : it(it)
    { }

    FlatMapIteratorAdapter operator++() {
        ++it;
        return FlatMapIteratorAdapter(it);
    }

    const Value& operator*() {
        return it->second;
    }

    bool operator==(FlatMapIteratorAdapter other) {
        return other.it == it;
    }

    bool operator!=(FlatMapIteratorAdapter other) {
        return !(*this == other);
    }

private:
    const_iterator it;
};

template<typename Map>
FlatMapIteratorAdapter<Map>
makeFlatMapIterator(const Map&, typename Map::const_iterator it) {
    return FlatMapIteratorAdapter<Map>(it);
}
