query on std::make_pair()

M

mark.van.dijk

Hi there, the C++ standard (section 20.2) defines std::make_pair() as:

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

On my system (.NET 2003) it is defined as:

template<class _Ty1, class _Ty2> inline
pair<_Ty1, _Ty2> __cdecl make_pair(_Ty1 _Val1, _Ty2 _Val2)
{
// return pair composed from arguments
return (pair<_Ty1, _Ty2>(_Val1, _Val2));
}

In particular, not that the arguments _Val1 and _Val2 are passed in by
value, and not by reference.

Is this a bug in the .NET library? or is this actually allowed by the
spec?
 
P

Pete Becker

Hi there, the C++ standard (section 20.2) defines std::make_pair() as:

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

On my system (.NET 2003) it is defined as:

template<class _Ty1, class _Ty2> inline
pair<_Ty1, _Ty2> __cdecl make_pair(_Ty1 _Val1, _Ty2 _Val2)
{
// return pair composed from arguments
return (pair<_Ty1, _Ty2>(_Val1, _Val2));
}

In particular, not that the arguments _Val1 and _Val2 are passed in by
value, and not by reference.

Is this a bug in the .NET library? or is this actually allowed by the
spec?

That was changed in the 2003 revision of the standard. It now says
 
P

Pete Becker

very interesting - what is the reason for this change?

make_pair("abc", 3);

used to be illegal, because the first argument creates a reference to an
array, which can't be copied. With the new version the type of the first
argument decays to pointer to const char.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top