Boost logo

Boost Users :

Subject: Re: [Boost-users] problem with boost::is_same
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-01-17 22:13:37


AMDG

Zachary Turner wrote:
> I have a question about the following code:
>
> typedef void(intArrayParamFunc)(int[]);
> typedef void(intPtrParamFunc)(int*);
>
>
> BOOST_STATIC_ASSERT((boost::is_same<intArrayParamFunc,intPtrParamFunc>::value));
> BOOST_STATIC_ASSERT((boost::is_same<int*,int[]>::value));
>
>
> cout << typeid(intArrayParamFunc).name() << endl;
> cout << typeid(intPtrParamFunc).name() << endl;
>
> cout << typeid(int*).name() << endl;
> cout << typeid(int[]).name() << endl;
>
> The first assert compiles but the second fails, which means that
> boost::is_same<> thinks that int* and int[] are different, but
> void(int[]) and void(int*) are the same. Why is this?
>
> The typeids print out the following:
>
> void __cdecl(int * const)
> void __cdecl(int *)
> int *
> int [0]
>
> I'm using Visual Studio 2008. I notice that typeid tells me that
> intArrayParamFunc is void(int* const). So why does boost::is_same<>
> compare them equal? Surely void(int* const) should not be the same
> type as void(int*).

Yes, it is the same. They are the same because the two
signatures are equivalent at the call site. The only
difference between

void f(const int);
and
void f(int);

is that in the first case f can modify its arguments. Since
the argument is passed by value, this has no impact on the caller.

> Unless this is just some obscure language subtlety I'm not aware of.
> So is this a bug in boost::is_same<>, a bug in my compiler, or no bugs
> at all and everything is working perfectly?

Everything is working perfectly. An array argument to a function is
really a pointer.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net