Re: Type of template member functions.
On 8 nov, 15:44, James Kanze <james.ka...@gmail.com> wrote:
On Nov 8, 5:00 pm, Elias Salom=E3o Helou Neto <eshn...@gmail.com> wrote:
Hello, the following program when compiled with GCC gives the output
that follows the listing:
#include <iostream>
#include <typeinfo>
struct A {
template< unsigned n >
void member( const double& );
};
int main()
{
std::cout << typeid( void (A::*) ( const double& ) ).name() << '\n'=
;
std::cout << typeid( &A::member< 0 > ).name() << '\n';
std::cout << typeid( &A::member< 1 > ).name() << '\n';
return( 0 );
}
Output:
M1AFvRKdE
PFvRKdE
PFvRKdE
Is that a GCC bug or the types of template member function and
member functions are not the same?
You can't call it a bug, since the standard doesn't say what
typeinfo().name() should return. From a QoI point of view, of
course, an implementation outputs such random text is seriously
deficient.
The reason I ask is because the following test always returns false:
template< class T >
class has_apply {
typedef char yes[1];
typedef char no[2];
template< class U, U u >
struct coerce {};
template< class U, unsigned n >
static yes& test( U*, coerce< void (U::*) ( const double& ) ,
&U::template apply< n > >* = 0 );
template< class U, unsigned n >
static no& test( ... );
public:
static const bool result = ( sizeof( yes ) == sizeof( test< T=
, 0
I don't see how it could do otherwise. You have one overload
of test which takes two or three arguments, another which can
take any number of arguments, and you call it with one.
Regardless of the types, the only match will be test(...).
I also don't see how this is related to typeid.
--
James Kanze
It takes one or two arguments: U* and coerce<>* = 0, take a look:
static yes& test( U*, coerce< void (U::*) ( const double& ),
&U::template apply< n > >* = 0 );
It would be related to typeid if a given type had a unique typeid,
because I thought
&A::member<1>
to be of type
void (A::*) ( const double& )
in which case my code would return true to has_apply< B >::result if B
were the following:
struct B {
template<unsigned n>
void apply( const double& );
};
since coerce<> would not fail to instantiate.