vendredi 14 janvier 2022

Iterator as the value of std::map

I'm trying to make a map with an iterator as the value. But the code below, unfortunately, does not compile.

template<class Base, class Result, bool Commutative>
struct Multimethod2
{
    typedef std::function<Result(Base*, Base*)> FUNC;
    typedef std::map<std::type_index, FUNC> INNER_MAP;
    typedef std::map<std::type_index, INNER_MAP::iterator> OUTER_MAP; //Don't compile :((

    OUTER_MAP omap_;
    INNER_MAP imap_;

    void addImpl(const std::type_info &t1, const std::type_info &t2, FUNC f )
    {

        auto iins = imap_.insert(std::pair<std::type_index, FUNC>(std::type_index(typeid(t2)), f)); //i get iterator iins.first
        auto oins = omap_.insert(std::pair<std::type_index, INNER_MAP>(std::type_index(typeid(t1)), iins.first)); //Don't compile :(((
    }

Aucun commentaire:

Enregistrer un commentaire