Re: Template<void> [ODE893JFHASTE]
Jakob Bieling ha scritto:
I thought it was illegal to use void as the template parameter? I
could not find any of that sort in my quick search in the Standard, tho
.. But I remember having worked around this before.
You can't use void as template parameter of the templates of the C++
standard library because 17.4.3.6/2 explicitly states that the effects
are undefined. However, the use of void as a template parameter in user
defined templates is perfectly legal. Of course, as any other type, when
it's substituted in the template it might produce ill-formed constructs,
but that's a completely different issue. For example:
template <typename T>
struct Value
{
T x;
};
template <typename T>
struct Pointer
{
T* x;
};
Value<void> illformed; // error: member of incomplete type
Pointer<void> legal; // ok
HTH,
Ganesh
PS: don't know for sure, but I expect 17.4.3.6/2 to be relaxed in some
way in the future to take into account some TR1 facilities like
tr1::shared_ptr<> and the type traits library which do allow incomplete
types as their parameter (what would be the use of tr1::is_void<> if
type void wasn't allowed? ;)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]