|
Boost : |
From: Ehsan Akhgari (ehsan_at_[hidden])
Date: 2003-09-13 23:13:07
> **BEGIN CODE
> #include <utility>
> #include <iostream>
>
> using namespace std;
>
> template<class Class,typename Type,Type Class::*PtrToMember>
> struct member:std::unary_function<Class,Type>
> {
> const Type& operator()(const Class&x)const
> {
> return x.*PtrToMember;
> }
>
> Type& operator()(Class &x)const
> {
> return x.*PtrToMember;
> }
> };
>
> typedef std::pair<int,int> pair_of_ints;
>
> int main()
> {
> pair_of_ints p(0,1);
> int i=member<pair_of_ints,int,&pair_of_ints::first>()(p);
> int j=member<pair_of_ints,int,&pair_of_ints::second>()(p);
>
> cout<<i<<","<<j<<endl;
> return 0;
> }
>
> ** END CODE**
>
> outputs 1,1 instead of 0,0. Somehow, the compiler cannot
> distinguish between the two instantiations of member<>.
Actually, the correct output should be "0,1", shouldn't it? I tested
this code with with some compilers on Windows, and here are the results:
Intel C++ 7.1 Build 20030307Z: 0,0
VC++ 7.1 Build 13.10.3077: 0,1
gcc 2.95.3-6 (mingw): 0,1
Digital Mars C++ 8.29n: couldn't compile:
$int i=member<pair_of_ints,int,&pair_of_ints::first>()(p);
$ ^
$1.cpp(22) : Error: illegal cast
$from: int pair<int ,int >::*
$to : int Class::*
$Internal error: newman 626
-------------
Ehsan Akhgari
List Owner: MSVC_at_[hidden]
[ Email: ehsan_at_[hidden] ]
[ WWW: http://www.beginthread.com/Ehsan ]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk