[Bug libstdc++/49778] New: Can't take pointer to std::make_pair in c++0x
bugzilla.gcc.gnu.com at sklep dot czarko.net
gcc-bugzilla@gcc.gnu.org
Mon Jul 18 16:24:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49778
Summary: Can't take pointer to std::make_pair in c++0x
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: bugzilla.gcc.gnu.com@sklep.czarko.net
When g++ is using c++0x standard the following code doesn't compile:
#include <algorithm>
#include <iostream>
#include <iterator>
#include <map>
#include <vector>
int main()
{
std::vector< int > inputs1 = { 1, 2, 3 };
std::vector< int > inputs2 = { 2, 5, 9 };
std::map< int, int > tmp;
std::transform(
inputs1.begin(),
inputs1.end(),
inputs2.begin(),
std::inserter( tmp, tmp.begin() ),
&std::make_pair< int, int >
);
for ( const std::pair< int, int > & i : tmp )
{
std::cout << "( " << i.first << " -> " << i.second << " )\n";
}
return 0;
}
The error is:
In file included from
/usr/lib/gcc/i686-redhat-linux/4.6.0/../../../../include/c++/4.6.0/algorithm:63:0,
from a.cpp:1:
/usr/lib/gcc/i686-redhat-linux/4.6.0/../../../../include/c++/4.6.0/bits/stl_algo.h:
In function ‘_OIter std::transform(_IIter1, _IIter1, _IIter2, _OIter,
_BinaryOperation) [with _IIter1 = __gnu_cxx::__normal_iterator<int*,
std::vector<int> >, _IIter2 = __gnu_cxx::__normal_iterator<int*,
std::vector<int> >, _OIter = std::insert_iterator<std::map<int, int> >,
_BinaryOperation = std::pair<int, int> (*)(int&&, int&&)]’:
a.cpp:19:9: instantiated from here
/usr/lib/gcc/i686-redhat-linux/4.6.0/../../../../include/c++/4.6.0/bits/stl_algo.h:4843:2:
error: invalid initialization of reference of type ‘int&&’ from expression of
type ‘int’
This can be fixed with a custom replacement for std::make_pair and using it
instead:
template < typename T1, typename T2 >
const std::pair< T1, T2 > MakePair( const T1 t1, const T2 t2 )
{
return std::pair< T1, T2 >( t1, t2 );
}
Note that this is similar to bug 43785 but I don't see here any way of avoiding
explicit template arguments.
More information about the Gcc-bugs
mailing list