R
Rob Williscroft
I have the following code , part of a trait to detect wether a type
has a member operator "Type" (), it works fine with g++ 3.4 (msvc
compiles it but it doesn't work for template'd operator T ()) but
with CBuilderX (EDG frontend) and Comeau's online compiler I get:
test.cpp:23: error invalid type conversion detected during
instantiation of "X:perator T() [with T=int &]" at line 41
I.e it instantiates X:perator< int & > int & () inside the
sizeof, any other compiler than EDG and I'd automaticly think
this was a compiler bug.
Thought's ?
#include <iostream>
#include <iomanip>
template < typename T, typename Type >
struct has_conversion_operator
{
private:
template < typename V, Type (V::*M)() > struct empty_t_;
template < typename U >
static char helper_f( empty_t_< U, &U:perator Type > * );
template < typename U >
static char (&helper_f( ... ))[2];
public:
static bool const bool_value =
( sizeof( helper_f< T >( 0 ) ) == sizeof( char ) )
;
};
struct X
{
template < typename T >
operator T () { return T(); } // line 23
};
int main()
{
using namespace std;
cout << boolalpha;
#define TEST( X, Y ) \
cout \
<< #X " operator " #Y "() " \
<< has_conversion_operator< X, Y >::bool_value \
<< '\n'
TEST( X, int );
TEST( X, int & ); // line 41
}
TIA.
Rob.
has a member operator "Type" (), it works fine with g++ 3.4 (msvc
compiles it but it doesn't work for template'd operator T ()) but
with CBuilderX (EDG frontend) and Comeau's online compiler I get:
test.cpp:23: error invalid type conversion detected during
instantiation of "X:perator T() [with T=int &]" at line 41
I.e it instantiates X:perator< int & > int & () inside the
sizeof, any other compiler than EDG and I'd automaticly think
this was a compiler bug.
Thought's ?
#include <iostream>
#include <iomanip>
template < typename T, typename Type >
struct has_conversion_operator
{
private:
template < typename V, Type (V::*M)() > struct empty_t_;
template < typename U >
static char helper_f( empty_t_< U, &U:perator Type > * );
template < typename U >
static char (&helper_f( ... ))[2];
public:
static bool const bool_value =
( sizeof( helper_f< T >( 0 ) ) == sizeof( char ) )
;
};
struct X
{
template < typename T >
operator T () { return T(); } // line 23
};
int main()
{
using namespace std;
cout << boolalpha;
#define TEST( X, Y ) \
cout \
<< #X " operator " #Y "() " \
<< has_conversion_operator< X, Y >::bool_value \
<< '\n'
TEST( X, int );
TEST( X, int & ); // line 41
}
TIA.
Rob.