query on std::make_pair()



 DEVELOP > c-Plus-Plus > query on std::make_pair()

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: ""
Date: 07 Mar 2005 01:09:16 PM
Object: query on std::make_pair()
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?
.

User: "Pete Becker"

Title: Re: query on std::make_pair() 07 Mar 2005 01:21:26 PM
wrote:

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

template < class T1 , class T2 >
pair <T1 , T2 > make_pair (T1 x , T2 y );
7 Returns: pair<T1, T2>(x, y).

--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
.
User: ""

Title: Re: query on std::make_pair() 07 Mar 2005 02:48:03 PM
very interesting - what is the reason for this change?
.
User: "Pete Becker"

Title: Re: query on std::make_pair() 07 Mar 2005 03:01:28 PM
wrote:

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.
--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
.




  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER