[typeof] enums are not integral types

The following sentence in typeof.htm: Other integral types, such as enums, need to be described explicitly with the BOOST_TYPEOF_INTEGRAL macro, like (BOOST_TYPEOF_INTEGRAL(MyEnum)) contrudicts with footnote in 3.9.1/7: 43) Therefore, enumerations (7.2) are not integral: however, enumerations can be promoted to int, unsigned int, long or unsigned long, as specified in 4.5 It should be easy to fix documentation. Not sure what to do with BOOST_TYPEOF_INTEGRAL, though. BTW, it reminds me of mpl::integral_c and this item in MPL TODO list: * vector_c, range_c et al. don't work with enumeration types * http://thread.gmane.org/gmane.comp.lib.boost.devel/116955 * http://article.gmane.org/gmane.comp.lib.boost.devel/116940 * http://thread.gmane.org/gmane.comp.lib.boost.user/9219 -- Alexander Nasonov

Alexander Nasonov <alnsn-boost <at> yandex.ru> writes:
BTW, it reminds me of mpl::integral_c and this item in MPL TODO list:
* vector_c, range_c et al. don't work with enumeration types * http://thread.gmane.org/gmane.comp.lib.boost.devel/116955 * http://article.gmane.org/gmane.comp.lib.boost.devel/116940 * http://thread.gmane.org/gmane.comp.lib.boost.user/9219
This is fine because mpl::integral_c represents integral constant which does not necessarily have integral type, right? -- Alexander Nasonov

"Alexander Nasonov" <alnsn-boost@yandex.ru> wrote
The following sentence in typeof.htm:
Other integral types, such as enums, need to be described explicitly with the BOOST_TYPEOF_INTEGRAL macro, like (BOOST_TYPEOF_INTEGRAL(MyEnum))
contrudicts with footnote in 3.9.1/7: 43) Therefore, enumerations (7.2) are not integral: however, enumerations can be promoted to int, unsigned int, long or unsigned long, as specified in 4.5
It should be easy to fix documentation. Not sure what to do with BOOST_TYPEOF_INTEGRAL, though.
BOOST_TYPEOF_INTEGRAL is used to denote template parameters which can be converted to compile-time integers, but, for some reason can't be recognized by the means of PP. Examples include integral types that are represented with more than two tokens (unsigned long int), enums, and dependent template parameters (template<class T, T n> class ...) It can also be used with any regular integral template parameters to avoid the "clever" PP code that is used to recognize it (which may be useful for porting). IOW, this maybe thouhgt of as if "unsigned int" is internally converted to BOOST_TYPEOF_INTEGRAL(unsigned int). I am not sure how such a beast should be called. Maybe we should introduce a couple of synonyms, such as: #define BOOST_TYPEOF_ENUM BOOST_TYPEOF_INTEGRAL #define BOOST_TYPEOF_DEPENDENT(x) BOOST_TYPEOF_INTEGRAL(P ## x) Regards, Arkadiy

On 6/28/05, Arkadiy Vertleyb <vertleyb@hotmail.com> wrote:
"Alexander Nasonov" <alnsn-boost@yandex.ru> wrote
The following sentence in typeof.htm:
Other integral types, such as enums, need to be described explicitly with the BOOST_TYPEOF_INTEGRAL macro, like (BOOST_TYPEOF_INTEGRAL(MyEnum))
contrudicts with footnote in 3.9.1/7: 43) Therefore, enumerations (7.2) are not integral: however, enumerations can be promoted to int, unsigned int, long or unsigned long, as specified in 4.5
It should be easy to fix documentation. Not sure what to do with BOOST_TYPEOF_INTEGRAL, though.
BOOST_TYPEOF_INTEGRAL is used to denote template parameters which can be converted to compile-time integers, but, for some reason can't be recognized by the means of PP. Examples include integral types that are represented with more than two tokens (unsigned long int), enums, and dependent template parameters (template<class T, T n> class ...) It can also be used with any regular integral template parameters to avoid the "clever" PP code that is used to recognize it (which may be useful for porting). IOW, this maybe thouhgt of as if "unsigned int" is internally converted to BOOST_TYPEOF_INTEGRAL(unsigned int).
I am not sure how such a beast should be called. Maybe we should introduce a couple of synonyms, such as:
#define BOOST_TYPEOF_ENUM BOOST_TYPEOF_INTEGRAL #define BOOST_TYPEOF_DEPENDENT(x) BOOST_TYPEOF_INTEGRAL(P ## x)
It would also be possible to add a bit of syntactic sugar to allow: enum color {...}; template<color> some_class {}; template<template <typename,int> class T> struct tt_class {}; template<typename A1,T A2> struct dependent_class {}; BOOST_TYPEOF_REGISTER_TEMPLATE(some_class, (enum(color)) ); BOOST_TYPEOF_REGISTER_TEMPLATE(tt_class, (template((typename)(int))) ); BOOST_TYPEOF_REGISTER_TEMPLATE(dependent_class, (typename)(dependent(0)) ); Regards, Peder
Regards, Arkadiy
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

"Peder Holt" <peder.holt@gmail.com> wrote
It would also be possible to add a bit of syntactic sugar to allow: enum color {...}; template<color> some_class {}; template<template <typename,int> class T> struct tt_class {}; template<typename A1,T A2> struct dependent_class {}; BOOST_TYPEOF_REGISTER_TEMPLATE(some_class, (enum(color)) ); BOOST_TYPEOF_REGISTER_TEMPLATE(tt_class, (template((typename)(int))) ); BOOST_TYPEOF_REGISTER_TEMPLATE(dependent_class, (typename)(dependent(0)) );
Unless I am missing something, there may be some problems with this. The first thing that needs to be done is pasting prefix and suffix to allow handling something like "unsigned int": PREFIX_unsigned int_SUFFIX However doing the same with, say, "enum(color)" would have to produce: PREFIX_enum(color)_SUFFIX, And I am pretty sure some preprocessors (for example GCC) would have a problem with pasting anything to ')'. But maybe you have something else in mind? Regards, Arkadiy

On 6/29/05, Arkadiy Vertleyb <vertleyb@hotmail.com> wrote:
"Peder Holt" <peder.holt@gmail.com> wrote
It would also be possible to add a bit of syntactic sugar to allow: enum color {...}; template<color> some_class {}; template<template <typename,int> class T> struct tt_class {}; template<typename A1,T A2> struct dependent_class {}; BOOST_TYPEOF_REGISTER_TEMPLATE(some_class, (enum(color)) ); BOOST_TYPEOF_REGISTER_TEMPLATE(tt_class, (template((typename)(int))) ); BOOST_TYPEOF_REGISTER_TEMPLATE(dependent_class, (typename)(dependent(0)) );
Unless I am missing something, there may be some problems with this.
The first thing that needs to be done is pasting prefix and suffix to allow handling something like "unsigned int":
PREFIX_unsigned int_SUFFIX
However doing the same with, say, "enum(color)" would have to produce:
PREFIX_enum(color)_SUFFIX,
And I am pretty sure some preprocessors (for example GCC) would have a problem with pasting anything to ')'.
But maybe you have something else in mind?
My idea was to let _SUFFIX expand to nothing, but you are probably right in that this is less portable. I have only tested it with VC7.1. I'll give it a go with GCC as well, to see what happens. Regards, Peder
Regards, Arkadiy
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (3)
-
Alexander Nasonov
-
Arkadiy Vertleyb
-
Peder Holt