lundi 23 janvier 2017

std::tie not working when using templates?

I am trying to use the std::tie to implement the operator< in order to create a map of structs that contain a set. The same code without templates seem that it works. I am getting this message code from my compiler:

/usr/include/c++/4.8/bits/stl_algobase.h:888: error: no match for 'operator<' (operand types are 'const SiPa' and 'const SiPa') if (*__first1 < *__first2) ^

Everything compiles if I comment the myMap.insert({akey, true}); line.

Any hints?

template<class I = int, class S = int>
  struct SiPa
    {
    I i;
    S s;
    };

  template<class I = int, class S = int>
  struct SiPaComparator
    {
    bool operator() (const SiPa<I, S>& first, const SiPa<I, S>& second) const
      {
      return std::tie(first.i, first.s) < std::tie(second.i, second.s);
      }
    };

  template<class I = int, class S = int>
  struct AKey
    {
    typedef std::set< SiPa<I, S>, SiPaComparator<I,S> > SetType;
    SetType keySet;
    I keyI;
    };

  template<class I = int, class S = int>
  struct AKeyComparator
    {
    bool operator() (const AKey<I, S>& first, const AKey<I, S>& second) const
      {
      return std::tie(first.keySet, first.keyI) <
         std::tie(second.keySet, second.keyI);
      }
    };


int main()
{
AKey<int,int> akey;

  std::map<AKey<int,int>, bool, AKeyComparator<int,int>> myMap;
  myMap.insert({akey, true});

}

Aucun commentaire:

Enregistrer un commentaire