473,390 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

A Complete ENUM++ (from Besser's CUJ article) Example

Hi,

Can anyone point me to a complete, compilable example
of Besser's ENUM++ mechanism? I downloaded it from
CUJ and gave it a try but got errors just trying to compile
the header enum.h.

--Randy Yates

Jan 6 '06 #1
10 3857
PS: Here's what I get. This is using gcc under fc3.

--RY
#include "enum.h"
int main(int argc, char **argv)
{
return 0;
}

cd /home/yates/modetest/host/app/modetest/
make -f enumpp.mak TARGET=native PLATFORM=linux
DSPROOT_DIR=/home/yates/modetest/ ATSIGN=
enumpp.mak:101: no file name for `include'
Building Component (enumpp) for Application enumpp
In file included from
/home/yates/modetest/host/app/modetest/enum.h:202,
from
/home/yates/modetest/host/app/modetest/enumpp.cpp:1:
/home/yates/modetest/host/app/modetest/StreamUDT.h: In function
`std::basic_ostream<_CharT, _Traits>&
KEA::stream_inserter(std::basic_ostream<_CharT, _Traits>&, const
UDT&)':
/home/yates/modetest/host/app/modetest/StreamUDT.h:96: error: expected
`;' before "prepost"
/home/yates/modetest/host/app/modetest/StreamUDT.h:97: error: `prepost'
undeclared (first use this function)
/home/yates/modetest/host/app/modetest/StreamUDT.h:97: error: (Each
undeclared identifier is reported only once for each function it
appears in.)
/home/yates/modetest/host/app/modetest/StreamUDT.h: In function
`std::basic_istream<_CharT, _Traits>&
KEA::stream_extractor(std::basic_istream<_CharT, _Traits>&, UDT&)':
/home/yates/modetest/host/app/modetest/StreamUDT.h:151: error: expected
`;' before "prepost"
/home/yates/modetest/host/app/modetest/StreamUDT.h:152: error:
`prepost' undeclared (first use this function)
In file included from
/home/yates/modetest/host/app/modetest/enumpp.cpp:1:
/home/yates/modetest/host/app/modetest/enum.h: At global scope:
/home/yates/modetest/host/app/modetest/enum.h:257: error: ISO C++
forbids declaration of `value_type' with no type
/home/yates/modetest/host/app/modetest/enum.h:257: error:
`::value_type' is not a valid declarator
/home/yates/modetest/host/app/modetest/enum.h:257: error: expected `;'
before "value_type"
/home/yates/modetest/host/app/modetest/enum.h:264: error: ISO C++
forbids declaration of `result_type' with no type
/home/yates/modetest/host/app/modetest/enum.h:264: error: expected `;'
before "operator"
/home/yates/modetest/host/app/modetest/enum.h:334: error: expected `;'
before '}' token
/home/yates/modetest/host/app/modetest/enum.h:338: error: ISO C++
forbids declaration of `result_type' with no type
/home/yates/modetest/host/app/modetest/enum.h:338: error: expected `;'
before "operator"
/home/yates/modetest/host/app/modetest/enum.h:344: error: expected `;'
before '}' token
/home/yates/modetest/host/app/modetest/enum.h:387: error: ISO C++
forbids declaration of `size_type' with no type
/home/yates/modetest/host/app/modetest/enum.h:387: error: `::size_type'
is not a valid declarator
/home/yates/modetest/host/app/modetest/enum.h:387: error: expected `;'
before "max_length"
/home/yates/modetest/host/app/modetest/enum.h:393: error: expected `;'
before "inline"
/home/yates/modetest/host/app/modetest/enum.h: In member function
`std::_Ios_Iostate KEA::_EnumSuper<_enumType, EnumSub,
N>::get_stream(std::basic_istream<_CharT2, _Traits2>&)':
/home/yates/modetest/host/app/modetest/enum.h:761: error: expected
primary-expression before "const"
/home/yates/modetest/host/app/modetest/enum.h:761: error: expected `;'
before "const"
/home/yates/modetest/host/app/modetest/enum.h:768: error:
`start_position' undeclared (first use this function)
/home/yates/modetest/host/app/modetest/enum.h: At global scope:
/home/yates/modetest/host/app/modetest/enum.h:789: error: expected
constructor, destructor, or type conversion before "_EnumSuper"
/home/yates/modetest/host/app/modetest/enum.h:789: error: expected `;'
before "_EnumSuper"
/home/yates/modetest/host/app/modetest/enum.h:805: error: expected
init-declarator before '&' token
/home/yates/modetest/host/app/modetest/enum.h:805: error: expected `;'
before '&' token
make: *** [/home/yates/modetest/host/app/modetest/nativelinux/enumpp.o]
Error 1

Compilation exited abnormally with code 2 at Fri Jan 6 11:41:16

Jan 6 '06 #2
PSS: I've also downloaded and installed boost.

--RY

Jan 6 '06 #3
More specificaly, here's what I got in trying to compile.

By the way, I have already downloaded and installed
boost. This is for gcc under fc3.

--RY

#include "enum.h"
int main(int argc, char **argv)
{
return 0;
}

cd /home/yates/modetest/host/app/modetest/
make -f enumpp.mak TARGET=native PLATFORM=linux
DSPROOT_DIR=/home/yates/modetest/ ATSIGN=
enumpp.mak:101: no file name for `include'
Building Component (enumpp) for Application enumpp
In file included from
/home/yates/modetest/host/app/modetest/enum.h:202,
from
/home/yates/modetest/host/app/modetest/enumpp.cpp:1:
/home/yates/modetest/host/app/modetest/StreamUDT.h: In function
`std::basic_ostream<_CharT, _Traits>&
KEA::stream_inserter(std::basic_ostream<_CharT, _Traits>&, const
UDT&)':
/home/yates/modetest/host/app/modetest/StreamUDT.h:96: error: expected
`;' before "prepost"
/home/yates/modetest/host/app/modetest/StreamUDT.h:97: error: `prepost'
undeclared (first use this function)
/home/yates/modetest/host/app/modetest/StreamUDT.h:97: error: (Each
undeclared identifier is reported only once for each function it
appears in.)
/home/yates/modetest/host/app/modetest/StreamUDT.h: In function
`std::basic_istream<_CharT, _Traits>&
KEA::stream_extractor(std::basic_istream<_CharT, _Traits>&, UDT&)':
/home/yates/modetest/host/app/modetest/StreamUDT.h:151: error: expected
`;' before "prepost"
/home/yates/modetest/host/app/modetest/StreamUDT.h:152: error:
`prepost' undeclared (first use this function)
In file included from
/home/yates/modetest/host/app/modetest/enumpp.cpp:1:
/home/yates/modetest/host/app/modetest/enum.h: At global scope:
/home/yates/modetest/host/app/modetest/enum.h:257: error: ISO C++
forbids declaration of `value_type' with no type
/home/yates/modetest/host/app/modetest/enum.h:257: error:
`::value_type' is not a valid declarator
/home/yates/modetest/host/app/modetest/enum.h:257: error: expected `;'
before "value_type"
/home/yates/modetest/host/app/modetest/enum.h:264: error: ISO C++
forbids declaration of `result_type' with no type
/home/yates/modetest/host/app/modetest/enum.h:264: error: expected `;'
before "operator"
/home/yates/modetest/host/app/modetest/enum.h:334: error: expected `;'
before '}' token
/home/yates/modetest/host/app/modetest/enum.h:338: error: ISO C++
forbids declaration of `result_type' with no type
/home/yates/modetest/host/app/modetest/enum.h:338: error: expected `;'
before "operator"
/home/yates/modetest/host/app/modetest/enum.h:344: error: expected `;'
before '}' token
/home/yates/modetest/host/app/modetest/enum.h:387: error: ISO C++
forbids declaration of `size_type' with no type
/home/yates/modetest/host/app/modetest/enum.h:387: error: `::size_type'
is not a valid declarator
/home/yates/modetest/host/app/modetest/enum.h:387: error: expected `;'
before "max_length"
/home/yates/modetest/host/app/modetest/enum.h:393: error: expected `;'
before "inline"
/home/yates/modetest/host/app/modetest/enum.h: In member function
`std::_Ios_Iostate KEA::_EnumSuper<_enumType, EnumSub,
N>::get_stream(std::basic_istream<_CharT2, _Traits2>&)':
/home/yates/modetest/host/app/modetest/enum.h:761: error: expected
primary-expression before "const"
/home/yates/modetest/host/app/modetest/enum.h:761: error: expected `;'
before "const"
/home/yates/modetest/host/app/modetest/enum.h:768: error:
`start_position' undeclared (first use this function)
/home/yates/modetest/host/app/modetest/enum.h: At global scope:
/home/yates/modetest/host/app/modetest/enum.h:789: error: expected
constructor, destructor, or type conversion before "_EnumSuper"
/home/yates/modetest/host/app/modetest/enum.h:789: error: expected `;'
before "_EnumSuper"
/home/yates/modetest/host/app/modetest/enum.h:805: error: expected
init-declarator before '&' token
/home/yates/modetest/host/app/modetest/enum.h:805: error: expected `;'
before '&' token
make: *** [/home/yates/modetest/host/app/modetest/nativelinux/enumpp.o]
Error 1

Compilation exited abnormally with code 2 at Fri Jan 6 11:41:16

Jan 7 '06 #4
Randy wrote:
Hi,

Can anyone point me to a complete, compilable example
of Besser's ENUM++ mechanism? I downloaded it from
CUJ and gave it a try but got errors just trying to compile
the header enum.h.

--Randy Yates


Can you give me a link to the code you downloaded?

Cheers! --M

Jan 7 '06 #5
Randy wrote:
Hi,

Can anyone point me to a complete, compilable example
of Besser's ENUM++ mechanism? I downloaded it from
CUJ and gave it a try but got errors just trying to compile
the header enum.h.

--Randy Yates


I found the code here:

ftp://ftp.cuj.com/pub/2003/cujjun2003.zip

The problem is that it appears Mr. Besser used an old (pre-C++03)
compiler. The problems can be fixed by adding the "typename" keyword at
various points (see
http://womble.decadentplace.org.uk/c...disambiguation)
and adding a few typedefs to obviate the type of problem discussed in
this FAQ:

http://www.parashift.com/c++-faq-lit...html#faq-35.18

For each of the two headers enum.h and StreamUDT.h, search for
"StringType::" and add "typename " before it like this:

typedef typename StringType::value_type value_type;

Do likewise for other types that are nested within template classes,
e.g.:

const typename std::basic_istream<charT, Traits>::pos_type
start_position=is.tellg();

and

typename _EnumSuper<_enumType, EnumSub, N>::StringType

Where a struct/class inherits from std::unary_function or
std::binary_function, add some typedefs in accord with the
aforementioned FAQ, e.g.:

struct Format: public std::unary_function<const char [], StringType>
{
typedef typename std::unary_function<const char [],
StringType>::result_type result_type;
typedef typename std::unary_function<const char [],
StringType>::argument_type argument_type;
// ...
};

and

struct StringLengthGreater
: public std::binary_function<const StringType*, const StringType*,
bool>
{
typedef typename std::binary_function<const char [],
StringType>::result_type result_type;
typedef typename std::binary_function<const char [],
StringType>::first_argument_type first_argument_type;
typedef typename std::binary_function<const char [],
StringType>::second_argument_type second_argument_type;
// ...
};

Then all the errors go away.

Cheers! --M

Jan 7 '06 #6
On 6 Jan 2006 11:25:41 -0800, "Randy" <ya***@ieee.org> wrote:
Can anyone point me to a complete, compilable example
of Besser's ENUM++ mechanism? I downloaded it from
CUJ and gave it a try but got errors just trying to compile
the header enum.h.


IMO, an "enum enhancement" that claims to be "easy to use" but "relies
on having the Boost preprocessor library [1] installed" isn't worth
the trouble.
It's also a good example of why CUJ has been 'discontinued'.

Best wishes,
Roland Pibinger
Jan 7 '06 #7
Hi M,

I still need some hand-holding as this is still not working
and it's beyond my C++ ability to find out why.

I made the changes you directed (I think) and am able
to compile error- and warning-free. The files are available
at

www.digitalsignallabs.com/enumpp.cpp
www.digitalsignallabs.com/enum.h
www.digitalsignallabs.com/StreamUDT.h

If, however, I add an enumeration declaration as Besser
shows in his article:

#include "enum.h"

int main(int argc, char **argv)
{
ENUM3(IdiotResponse, Yup, Nope, IDunno);

return 0;
}
I get errors:
g++ -c `cyg2dos /home/yates/modetest/host/app/modetest/enumpp.cpp`
-O3 -Wall -pthread -g -I /home/yates/modetest/host/inc/ -I
/home/yates/modetest/dsp/inc/ -DTARGET_NATIVE -DPLATFORM_LINUX -o
/home/yates/modetest/host/app/modetest/nativelinux/enumpp.o
/home/yates/modetest/host/app/modetest/enumpp.cpp:5:1: macro
"ENUM_GLOBAL_VALUES" passed 4 arguments, but takes just 2
/home/yates/modetest/host/app/modetest/enumpp.cpp: In function `int
main(int, char**)':
/home/yates/modetest/host/app/modetest/enumpp.cpp:5: error:
`ENUM_GLOBAL_VALUES' undeclared (first use this function)
/home/yates/modetest/host/app/modetest/enumpp.cpp:5: error: (Each
undeclared identifier is reported only once for each function it
appears in.)
/home/yates/modetest/host/app/modetest/enumpp.cpp:5: error: expected
`;' before "class"
Please help some more!

--Randy

Jan 9 '06 #8
Randy wrote:
Hi M,

I still need some hand-holding as this is still not working
and it's beyond my C++ ability to find out why.

I made the changes you directed (I think) and am able
to compile error- and warning-free. The files are available
at

www.digitalsignallabs.com/enumpp.cpp
www.digitalsignallabs.com/enum.h
www.digitalsignallabs.com/StreamUDT.h
Those look good.
If, however, I add an enumeration declaration as Besser
shows in his article:

#include "enum.h"

int main(int argc, char **argv)
{
ENUM3(IdiotResponse, Yup, Nope, IDunno);

return 0;
}
I get errors:
g++ -c `cyg2dos /home/yates/modetest/host/app/modetest/enumpp.cpp`
-O3 -Wall -pthread -g -I /home/yates/modetest/host/inc/ -I
/home/yates/modetest/dsp/inc/ -DTARGET_NATIVE -DPLATFORM_LINUX -o
/home/yates/modetest/host/app/modetest/nativelinux/enumpp.o
/home/yates/modetest/host/app/modetest/enumpp.cpp:5:1: macro
"ENUM_GLOBAL_VALUES" passed 4 arguments, but takes just 2
/home/yates/modetest/host/app/modetest/enumpp.cpp: In function `int
main(int, char**)':
/home/yates/modetest/host/app/modetest/enumpp.cpp:5: error:
`ENUM_GLOBAL_VALUES' undeclared (first use this function)
/home/yates/modetest/host/app/modetest/enumpp.cpp:5: error: (Each
undeclared identifier is reported only once for each function it
appears in.)
/home/yates/modetest/host/app/modetest/enumpp.cpp:5: error: expected
`;' before "class"
Please help some more!

--Randy


You might need to take the ENUM3 declaration outside of the function
body to give it external linkage. If I do that, the example works fine
with VC++6, which is the compiler the author used.

I did a somewhat cursory look at things on g++ 3.4.4, on which your
code doesn't work for me either, but I didn't see anything obviously
wrong. To reduce the noise, you can see the preprocessor error alone by
using the -E option, which yields:

macro "ENUM_GLOBAL_VALUES" passed 4 arguments, but takes just 2

The ultimate problem seems to be with the use of this macro:

#define ENUM_LIST(size, tuple) \
BOOST_PP_LIST_ENUM(BOOST_PP_TUPLE_TO_LIST(size, tuple))

I'm no Boost PP expert, and so I'll have to recommend that you take
this to the Boost User list at
http://lists.boost.org/mailman/listinfo.cgi/boost-users or perhaps to a
GNU forum. I didn't see anything about a compiler incompatibility on
Boost's website (indeed,
http://engineering.meta-comm.com/boo...processor.html
seems to indicate that it should be fully functional), so I'd talk to
the folks in the know.

I also briefly tried tracking down the author of the article to no
avail. You might be able to find him out there somewhere, and ask him
for help directly.

Sorry I can't be more help.

Cheers! --M

Jan 10 '06 #9
mlimber wrote:
using the -E option, which yields:

macro "ENUM_GLOBAL_VALUES" passed 4 arguments, but takes just 2

The ultimate problem seems to be with the use of this macro:

#define ENUM_LIST(size, tuple) \
BOOST_PP_LIST_ENUM(BOOST_PP_TUPLE_TO_LIST(size, tuple))

I'm no Boost PP expert, and so I'll have to recommend that you take
this to the Boost User list at
http://lists.boost.org/mailman/listinfo.cgi/boost-users or perhaps to
a
GNU forum. I didn't see anything about a compiler incompatibility on
Boost's website (indeed,
http://engineering.meta-comm.com/boo...processor.html
seems to indicate that it should be fully functional), so I'd talk to
the folks in the know.

I also briefly tried tracking down the author of the article to no
avail. You might be able to find him out there somewhere, and ask him
for help directly.

Sorry I can't be more help.


The quick dirty fix for your preprocessing error... First, include
<boost/preprocessor/tuple/rem.hpp> with the rest of the Boost.Preprocessor
includes. Then alter line 830 (in the definition of BEGIN_ENUM) from...

ENUM_GLOBAL_VALUES(type, value_list) \

....to...

ENUM_GLOBAL_VALUES(type, BOOST_PP_TUPLE_REM(N)(value_list)) \

Regards,
Paul Mensonides
Jan 10 '06 #10
"mlimber" <ml*****@gmail.com> writes:
[...]
Sorry I can't be more help.


No problem, M, and thanks for your help.

FYI, I've written my CEnum class to do what I needed. It took a few
hours, but it's suitable to the task and I've got my automatic
inserters and extractors. It's probably very unsophisticated
compared to the kinds of tools you guys are used to seeing, but
if you're interested I'll post it.
--
% Randy Yates % "The dreamer, the unwoken fool -
%% Fuquay-Varina, NC % in dreams, no pain will kiss the brow..."
%%% 919-577-9882 %
%%%% <ya***@ieee.org> % 'Eldorado Overture', *Eldorado*, ELO
http://home.earthlink.net/~yatescr
Jan 11 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: AngleWyrm | last post by:
"The C++ Programming Language" by Bjarne Stroustrup, copyright 1997 by AT&T, section 4.8 (pp 77): "A value of integral type may be explicitly converted to an enumeration type. The result of such a...
8
by: Klaus Schneider | last post by:
Hi all! I'm having trouble with a template function with variable arguments when I parse an enum type as variable argument. Example: template <class T> bool test(int num, ...) { va_list ap;...
18
by: Nebula | last post by:
Consider enum Side {Back,Front,Top,Bottom}; enum Side a; Now, why is a = 124; legal (well it really is an integer, but still, checking could be performed..) ? Wouldn't enums be more useful if...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
18
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! I have created an enum list like this: enum myEnum : int { This = 2, That, NewVal = 10, LastItm
2
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
10
by: kar1107 | last post by:
Hi all, Can the compiler chose the type of an enum to be signed or unsigned int? I thought it must be int; looks like it changes based on the assigned values. Below if I don't initialize...
34
by: Steven Nagy | last post by:
So I was needing some extra power from my enums and implemented the typesafe enum pattern. And it got me to thinking... why should I EVER use standard enums? There's now a nice little code...
185
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.