0

I want to avoid using the std::pair() constructor or std::make_pair() functions while inserting into a map. I also want to know the success status of the insert operation, so I cannot use operator[]. I tried the following code but it produces a compile error.

template<typename TKey, typename TVal>
class Map
{
   private :
      std::map<TKey, TVal> m_holder;

   public :
      bool insert(TKey key, TVal val)
      {
         std::pair<std::map<TKey, TVal>::iterator, bool> ret;
         /* ret = m_holder.insert(std::make_pair(key, val)); */
         return 0;
      }
};

int main()
{
   return 0;
}

Error :

Hello.cpp: In member function `bool Map<TKey, TVal>::insert(TKey, TVal)':
Hello.cpp:13: error: type/value mismatch at argument 1 in template parameter list for `template<class _T1, class _T2> struct std::pair'
Hello.cpp:13: error:   expected a type, got ` std::map<TKey,TVal,std::less<_Key>,std::allocator<std::pair<const _Key, _Tp> > >::iterator'
Hello.cpp:13: error: invalid type in declaration before ';' token

Help me solve the problem.

seh
  • 14,999
  • 2
  • 48
  • 58
Dinesh
  • 1,825
  • 5
  • 31
  • 40
  • 1
    possible duplicate of [Where and why do I have to put the "template" and "typename" keywords?](http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) – Piotr Skotnicki Oct 01 '14 at 13:20

1 Answers1

1
std::pair<typename std::map<TKey, TVal>::iterator, bool> ret;
//        ~~~~~~~^
Piotr Skotnicki
  • 46,953
  • 7
  • 118
  • 160