G
Gianni Mariani
The 3 compilers I tried all did different things.
gcc 3.4.0 ICE's (Bug 15480)
MS C++ 7.1 has meaningless diags
Comeau accepts the code
Obviously this is not somthing I'll be using until we get the compilers
doing the right thing, but I do want to report the appropriate errors.
BTW, I think the code is valid. It does the thing I was trying to do
before (template has_member) that I got zero response on (...checks
armpits for odor...
).
============================================================================
typedef char MPT_False;
struct MPT_True { int m[2]; };
template <unsigned int w_siz>
struct MPT_IntToType
{
typedef char type[ 1 ];
};
template <typename w_D>
struct MPT_Finder_Member
{
template <typename w_T>
static MPT_True finder(
const w_T *,
typename MPT_IntToType<
static MPT_False finder( const w_D * );
};
template <typename w_D >
struct MPT_ContainsFuncMember
{
struct DerivedClass : w_D
{
};
typedef DerivedClass * DerivedClassp;
enum {
value = (
sizeof( MPT_Finder_Member<w_D>::finder( DerivedClassp() ) )
== sizeof( MPT_True )
)
};
};
struct A
{
};
struct B
{
int Function();
};
#include <iostream>
int main()
{
std::cout << MPT_ContainsFuncMember<A>::value << "\n";
std::cout << MPT_ContainsFuncMember<B>::value << "\n";
}
=========================================================================
MSC++ sez
xx5.cpp
xx5.cpp(21) : error C2955: 'MPT_IntToType' : use of class template
requires template argument list
xx5.cpp(11) : see declaration of 'MPT_IntToType'
xx5.cpp(39) : see reference to class template instantiation
'MPT_Finder_Member<w_D>' being compiled
with
[
w_D=A
]
xx5.cpp(60) : see reference to class template instantiation
'MPT_ContainsFuncMember<w_D>' being compiled
with
[
w_D=A
]
xx5.cpp(21) : error C2955: 'MPT_IntToType' : use of class template
requires template argument list
xx5.cpp(11) : see declaration of 'MPT_IntToType'
xx5.cpp(39) : see reference to class template instantiation
'MPT_Finder_Member<w_D>' being compiled
with
[
w_D=B
]
xx5.cpp(61) : see reference to class template instantiation
'MPT_ContainsFuncMember<w_D>' being compiled
with
[
w_D=B
]
gcc 3.4.0 ICE's (Bug 15480)
MS C++ 7.1 has meaningless diags
Comeau accepts the code
Obviously this is not somthing I'll be using until we get the compilers
doing the right thing, but I do want to report the appropriate errors.
BTW, I think the code is valid. It does the thing I was trying to do
before (template has_member) that I got zero response on (...checks
armpits for odor...
============================================================================
typedef char MPT_False;
struct MPT_True { int m[2]; };
template <unsigned int w_siz>
struct MPT_IntToType
{
typedef char type[ 1 ];
};
template <typename w_D>
struct MPT_Finder_Member
{
template <typename w_T>
static MPT_True finder(
const w_T *,
typename MPT_IntToType<
);sizeof(static_cast said:::type * = 0
static MPT_False finder( const w_D * );
};
template <typename w_D >
struct MPT_ContainsFuncMember
{
struct DerivedClass : w_D
{
};
typedef DerivedClass * DerivedClassp;
enum {
value = (
sizeof( MPT_Finder_Member<w_D>::finder( DerivedClassp() ) )
== sizeof( MPT_True )
)
};
};
struct A
{
};
struct B
{
int Function();
};
#include <iostream>
int main()
{
std::cout << MPT_ContainsFuncMember<A>::value << "\n";
std::cout << MPT_ContainsFuncMember<B>::value << "\n";
}
=========================================================================
MSC++ sez
xx5.cpp
xx5.cpp(21) : error C2955: 'MPT_IntToType' : use of class template
requires template argument list
xx5.cpp(11) : see declaration of 'MPT_IntToType'
xx5.cpp(39) : see reference to class template instantiation
'MPT_Finder_Member<w_D>' being compiled
with
[
w_D=A
]
xx5.cpp(60) : see reference to class template instantiation
'MPT_ContainsFuncMember<w_D>' being compiled
with
[
w_D=A
]
xx5.cpp(21) : error C2955: 'MPT_IntToType' : use of class template
requires template argument list
xx5.cpp(11) : see declaration of 'MPT_IntToType'
xx5.cpp(39) : see reference to class template instantiation
'MPT_Finder_Member<w_D>' being compiled
with
[
w_D=B
]
xx5.cpp(61) : see reference to class template instantiation
'MPT_ContainsFuncMember<w_D>' being compiled
with
[
w_D=B
]