Topic: Again About Min and Max Values of Enumeration
Author: Paul Grealish <paul.grealish@uk.geopak-tms.com>
Date: 1998/11/21 Raw View
Alex Vinokur wrote:
>
> Hi,
>
> I would like to propose the method "How to Get Min and Max Values of Enumeration".
> It is not very elegant method but maybe sometimes it will be useful.
>
> (snip)
Looks similar to some material at:
http://www.edm2.com/0405/enumeration.html
--
+---------------------------------+
| Paul Grealish |
| GEOPAK-TMS Limited |
| Cambridge, England |
| paul.grealish@uk.geopak-tms.com |
+---------------------------------+
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Alex Vinokur <alexander.vinokur@telrad.co.il>
Date: 1998/11/18 Raw View
Hi,
I would like to propose the method "How to Get Min and Max Values of Enumeration".
It is not very elegant method but maybe sometimes it will be useful.
Thanks,
Alex
//###################### PROGRAM ###########################################
#include <stdio.h>
#include <iostream.h>
#define GET_MIN_ENUM_VALUE(ename) (Min_##ename + 1)
#define GET_MAX_ENUM_VALUE(ename) (Max_##ename - 1)
enum AAA
{
Min_AAA, // The name must be Min_<enum_name>
aaa1,
aaa2,
aaa3,
aaa4,
aaa5,
Max_AAA // The name must be Max_<enum_name>
};
enum BBB
{
Min_BBB = 14,
bbb1,
bbb2,
bbb3,
bbb4 = 50,
bbb5,
Max_BBB
};
enum CCC
{
Min_CCC = 6,
ccc1,
ccc2,
ccc3,
ccc4,
ccc5,
Max_CCC
};
int main()
{
cout << GET_MIN_ENUM_VALUE (AAA) << " - " << GET_MAX_ENUM_VALUE (AAA) << endl;
cout << GET_MIN_ENUM_VALUE (BBB) << " - " << GET_MAX_ENUM_VALUE (BBB) << endl;
cout << GET_MIN_ENUM_VALUE (CCC) << " - " << GET_MAX_ENUM_VALUE (CCC) << endl;
return 0;
}
//###################### RESULTS OF THE RUNNING ############################
1 - 5
15 - 51
7 - 11
//##########################################################################
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]