std::pair<reference,reference>

Benjamin Kosnik bkoz@redhat.com
Thu May 18 05:22:00 GMT 2006


> I wonder whether it would be possible to add some specializations of
> pair for it to work even one of its template arguments is a reference.
> Below is the specialization example for the case  when the two
> parameters are references. Obviously, DR 106 (if/when
> adopted/implemented) is a better fix, but in the meantime, maybe a awful
> trick like this one could be considered as a quality of
> implementation....

Hmm. Are you sure you have the right number? 
 
include <utility>

int main()
{
 using namespace std;

 int i = 6;
 int j = 7;
 int& r1 = i;
 int& r2 = j;
 make_pair(r1, r2);
 pair<r1, r2> p;
}

%g++ -c pair.cc
pair.cc: In function 'int main()':
pair.cc:12: error: 'r1' cannot appear in a constant-expression
pair.cc:12: error: 'r2' cannot appear in a constant-expression
pair.cc:12: error: template argument 1 is invalid
pair.cc:12: error: template argument 2 is invalid
pair.cc:12: error: invalid type in declaration before ';' token

This, you mean?

> If acceptable, I would be glad to implement and test it.

Sure.

-benjamin



More information about the Libstdc++ mailing list