On Friday 20 February 2015 12:53:24 Matthew Woehlke wrote:
>   for (auto const i : qtEnumerate(map))
> 
> Maybe it would be nice for Qt to provide one or both of these?

Sounds easy enough. Want to give it a try?

Note that this should also work for foreach:

        foreach (const auto i, qtEnumerate(map))

Something like:

template <typename Map>
struct QEnumerateMap : private Map
{
        struct const_iterator {
                typename Map::iterator i;
                iterator(typename Map::iterator i) : i(i) {}

                // need to return by value
                std::pair<typename Map::key_type, typename Map::value_type>
                value() const
                { return std::make_pair(i.key(), i.value()); }
        };

        const_iterator begin() const
        { return iterator(Map::begin()); }
        const_iterator end() const
        { return iterator(Map::end()); }
};
-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

_______________________________________________
Development mailing list
[email protected]
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to