[C++-sig] Re: Pyste bug with unnamed enums
David Abrahams
dave at boost-consulting.com
Tue Feb 17 17:38:18 CET 2004
"Roman Yakovenko" <roman.yakovenko at actimize.com> writes:
> Hi. I found bug in Pyste.
>
> Description:
> In your code you have 2 unnamed enum definitions
>
> enum { SOME_CONST_1 = 32 };
> enum { SOME_CONST_2 = 46 };
>
> after running pyste on this code you will get
>
> // Unique type for unnamed enums
> #ifndef PYSTE_UNIQUE_INT_DEFINED
> #define PYSTE_UNIQUE_INT_DEFINED
> template<int num>
> struct UniqueInt {
> int v;
> enum { value=num };
> UniqueInt(int v_):
> v(v_)
> {}
> operator int() const
> { return v; }
> };
> #endif // PYSTE_UNIQUE_INT_DEFINED
>
> generated twice ( if you generate your code to the same module ).
>
> The possible solution are:
> 1. To ask David Abrahams how we should export unnamed enums (
> defined within class and within some namespace ).
Name them. If you can't name them, you can't export them. You can't
even pass them through a function template:
enum { x = 1 };
template <class T>
int f(T);
int y = f(x); // error
Sorry.
> 2. To use unnamed enums as global constants for enums defined within namespace.
> To define new class attribute if enum defined within class.
> 3. To put definition of UniqueInt within BPL
:(
I don't really know what UniqueInt is supposed to do, but I don't
love it because it's not unique ;-)
enum { x = 1 }
enum { y = 1 }
BOOST_STATIC_ASSERT((boost::is_same<UniqueInt<x>,UniqueInt<y> >::value));
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list