🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3853

template and const

#3853
From: Lars Farm
Date: Thu, 28 Mar 1996 17:31
47 lines
2112 bytes
Is "pair<T1,T2>" valid as function argument where the 
declaration expects "const pair<const T1,T2>&"?

This comes up in the standard library map<K,V>::insert and make_pair

    template <class T1, class T2>
    struct pair {
      T1 first;
      T2 second;
      pair();
      pair(const T1& x, const T2& y);
    };

    template <class T1, class T2> 
    pair<T1,T2> make_pair(const T1&, const T2&);

    template <class Key, class T,
              class Compare = less<Key>,
              class Allocator = allocator>
    class map {
      ...
      typedef pair<const Key, T> value_type;
      ...
      pair<iterator, bool> insert(const value_type& x);
      ...
    };

void f( string a, string b )
{
    map<string,string> m;
    ...
    m.insert( make_pair(a,b) ); // valid c++?

make_pair yields a temporary of type pair<string,string>. temporaries are
const. insert() wants a const pair<const string,string>. So they should
both be a pair of constant strings, right? but the compilers I have access
to disagrees.

--
Lars Farm, lars.farm@nts.mh.se
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Technical Details
Message-ID: <AD8043589668101EA@sleipner.nts.mh.se>
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: lars.farm@nts.mh.se (Lars Farm)
Newsgroups: comp.std.c++
Subject: template and const
Date: 28 Mar 1996 09:31:42 PST
Organization: pv
Approved: austern@isolde.mti.sgi.com
Message-ID: <AD8043589668101EA@sleipner.nts.mh.se>
NNTP-Posting-Host: isolde.mti.sgi.com
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Original-Date: Thu, 28 Mar 1996 13:23:36 +0100
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMVrM/0y4NqrwXLNJAQH8CAH9EQBxHsTaclpS4OWpnaUS9R3/kcyFT6HB
 9zLl0gOlbGURd+0VMRAxJEBmS/eEmysvxofs/VOovtxTYF0+sej3sA==
 =40b3
Originator: austern@isolde.mti.sgi.com