jeudi 21 mai 2015

Template function receiving any standard map

I am writing a function that should receives one of (std::map, std::multimap, std::unordered_map or std::unordered_multimap). My code is as follow:

template<template <class, class> class Map, typename Coord>
    inline typename std::enable_if<std::is_arithmetic<Coord>::value>::type 
    filter(Map<Coord, Coord>& map, Coord step = 2) {
            for (auto it = std::begin(map); it != std::end(map);) {
                if (it->second - it->first <= step){
                    it = diagram.erase(it);
                }
                else
                    ++it;
            }
        }

The template template parameter Map does not generalize for all types of maps. The std::map and std::multimap receive four template parameters, and std::unordered_map and std::unordered_multimap receive five template parameters. This implies that I can not solve the problem with a template template parameter. Is there any way to solve this with the constraint that all maps must have KeyType = ValeType = Coord? I would not like to specify explicitly the parameters types in a call to filter.

Aucun commentaire:

Enregistrer un commentaire