?
Solved

Tvoid?  tCIDLib?

Posted on 2004-11-28
4
Medium Priority
?
448 Views
Last Modified: 2012-06-21
I am not much of a c++ programmer, but I am reading http://www.edm2.com/0405/enumeration.html.  Here we have some code from that article:

      



// A macro to generate the standard enum functions
#define StdEnumTricks(eEnumType) \
inline void operator++(eEnumType& eVal) \
{ \
    eVal = eEnumType(eVal+1); \
} \
\
inline void operator++(eEnumType& eVal, int)  \
{ \
    eVal = eEnumType(eVal+1); \
} \
\
inline void operator--(eEnumType& eVal) \
{ \
    eVal = eEnumType(eVal-1); \
} \
\
inline tCIDLib::TVoid operator--(eEnumType& eVal, int)  \
{ \
    eVal = eEnumType(eVal-1); \
} \
\
inline eEnumType eEnumMax(eEnumType) \
{ \
    return eEnumType##_Max; \
} \
\
inline eEnumType eEnumMin(eEnumType) \
{ \
    return eEnumType##_Min; \


Notice the tCIDLIB::Tvoid.  

What is going on here?  What is TVoid used for?  Is the library reference portable?  I will be using gcc.
0
Comment
Question by:astar666
4 Comments
 
LVL 19

Assisted Solution

by:mrwad99
mrwad99 earned 200 total points
ID: 12690814
??!  That is completely new to me !

One thing is for sure, and that is that it is not part of the standard.  I think what has happened is that this is some custom type (I cannot find any mention of it on MSDN, so it is not MS specific) defined to help this code you are looking at.

Regarding portability, then I would not imagine that that would be an issue, since it is almost certainly something that is defined within the code that is using it.  

But nonetheless, this is interesting, and it will be cool to hear what the real gurus of C++ have to say on this...
0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 200 total points
ID: 12690902
Hi astar666,
You can be sure nor Tvoid nor tCIDLib are part of any C++ standard, so there are user-defined class and member.


Good luck,
Jaime.
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 200 total points
ID: 12690911
Check out the other files - I am pretty sure that somewhere there is a

typedef void TVoid;

The library seems to use it's own type for 'void', that's all. However, I cannot see any advantage here...
0
 
LVL 11

Accepted Solution

by:
bcladd earned 400 total points
ID: 12690954
(1) I don't remember tCIDLib from the OS/2 days (but it has been a while). Looking at the original source, it looks like an editing error (the other return types look like they, too, could have that return type but were edited to the standard void type).

(2) I, personally, don't like the void return type for the increment/decrement operators. Though it might be evil, it is possible to use increment operators inside of other, larger expressions. Consider an array indexed by daysOfTheWeek:

while (theDay != eEnumMax(daysOfTheWeek)) {
  cout << stuff[theDay++] << endl;
}

This would not work with the given macro. Might make more sense to edit it to
// A macro to generate the standard enum functions
#define StdEnumTricks(eEnumType) \
inline eEnumType operator++(eEnumType& eVal) \
{ \
    eVal = eEnumType(eVal+1); \
    return eVal; \
} \
\
inline eEnumType operator++(eEnumType& eVal, int)  \
{ \
    eEnumType eTemp = eVal; \
    eVal = eEnumType(eVal+1); \
    return eTemp; \
} \
\
inline eEnumType operator--(eEnumType& eVal) \
{ \
    eVal = eEnumType(eVal-1); \
    return eVal; \
} \
\
inline eEnumType operator--(eEnumType& eVal, int)  \
{ \
    eEnumType eTemp = eVal; \
    eVal = eEnumType(eVal-1); \
    return eTemp; \
} \
\
inline eEnumType eEnumMax(eEnumType) \
{ \
    return eEnumType##_Max; \
} \
\
inline eEnumType eEnumMin(eEnumType) \
{ \
    return eEnumType##_Min; \
}

This way you return a pre or post incremented (decremented) value from the operator which is much more what is expected.

-bcl
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question