is_enum implementation, why add_reference ?

Hello, I'm currently having a look at boost's type traits implementation. At the moment, I'm curious about is_enum. Can please someone explain me why add_reference is applied before testing convertibility to int_convertible ??? Trying to find more information about how to detect enum types, I only found this reference http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/898b98475c804f5b/0e6e68dd917ff1fb?hl=en& where it's explained that "An enum is a user-defined type that is convertible to int without an user-defined conversion (and two user-defined conversions in a row are illegal, so you can detect that)." Thank you. Regards, Gregory.

Grégory Pakosz wrote:
Hello,
I'm currently having a look at boost's type traits implementation. At the moment, I'm curious about is_enum. Can please someone explain me why add_reference is applied before testing convertibility to int_convertible ???
The class needs to declare an object of type T, and then try and see if it converts or not... but you may not be able to declare an object of type T (for example T may be abstract), where as you an always declare a reference to T, and the conversion rules work the same. HTH, John.

John Maddock <john <at> johnmaddock.co.uk> writes:
Grégory Pakosz wrote:
Hello,
I'm currently having a look at boost's type traits implementation. At the moment, I'm curious about is_enum. Can please someone explain me why add_reference is applied before testing convertibility to int_convertible ???
The class needs to declare an object of type T, and then try and see if it converts or not... but you may not be able to declare an object of type T (for example T may be abstract), where as you an always declare a reference to T, and the conversion rules work the same.
HTH, John.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thank you John for the explanation. To make things clear, if is_convertible was implemented the same way as loki's Conversion, that is making use of a "T makeT()" function, then add_reference would not be needed right ? Gregory.

Grégory Pakosz wrote:
To make things clear, if is_convertible was implemented the same way as loki's Conversion, that is making use of a "T makeT()" function, then add_reference would not be needed right ?
Hmmm, there are a limited number of things you can return from a function call: it still wouldn't work for abstract classes, and probably function types as well. John.
participants (2)
-
Grégory Pakosz
-
John Maddock