Re: transform, make_pair, and rvalues
On Tuesday, April 15, 2014 7:33:15 AM UTC+2, James K. Lowden wrote:
On Sun, 13 Apr 2014 13:51:55 CST
Having looked further into this today, AFAICT:
1. std::transform requires explicit instantiation of any templated
function argument.
2. No explicit instantiation of make_pair is portable across
C++98 and C++11.
At least the second fact was known to the committee and to
implementors in 2010.
My impression is that because make_pair was invented for type
deduction, the lack of backward compatibility for explicit
instantiation was deemed unimportant. It's not clear to me if
the use
of make_pair in std algorithms was considered, or if in fact the
compiler is supposed to deduce template parameters in that case.
Regards,
--jkl
I think the Standard Library lacks some polymorphic function objects.
For example, existing function objects like std::less<T>...
Today I'd rather see something like:
struct less {
typedef bool result_type;
template < class T, class U >
bool operator()( T const& t, U const& u ) const
{ return t < u; }
};
Here 'polymorphic' means the function object isn't a tempalte any
more. Instead, the function-call operator is templated. Therefore
you don't provide template parameters when passing the functor
to an algorithm or container, but instead the arguments are
deduced when the algorithm or container calls the functor.
And for std::make_pair similarly a polymorphic function object
can be written. In fact, Boost.Proto provides one:
#include <boost/proto/functional/std/utility.hpp>
#include <algorithm>
#include <map>
#include <stdint.h>
#include <vector>
namespace prf = boost::proto::functional;
int main()
{
std::vector<int> a;
std::vector<uint64_t> b;
std::map<int,uint64_t> c;
std::transform( a.begin(), a.end(), b.begin(),
std::inserter(c, c.begin()), prf::make_pair() );
}
This should work with both C++ standards.
Regards,
Kris
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]