|
Boost : |
From: Andy Little (andy_at_[hidden])
Date: 2004-01-10 03:57:21
"David Abrahams" <dave_at_[hidden]> wrote
> "Fernando Cacciola" <fernando_cacciola_at_[hidden]> writes:
> > (2)
> > VC7.1 doesn't like the implementation of "mpl::equal_to" when the
operands
> > are "mpl::integral_c" of ENUMERATION type.
Arent enums different enough from integers to have their own 'enum_c'
1)
enum-->int// ok , int --> enum //error.
2)
enums are best suited for use where you need a Closed set
of arbitrarily different values. They should not really be used for maths,
because there is no requirement on enums that they go beyond a certain
range(C++3rdEd 4.8):
enum my{x = 1}; // acceptable that any 'my' is stored in 1 bit
// Might do what you want but If stored in 1 bit ...ouch!
static_cast<my>(x+x);
Hence I am a bit uneasy using enums with integral_c. next,prior etc
3) enums can be differentiated:
#include <iostream>
enum my{x=1};
enum your{y=0};
void func(int x)
{
std::cout <<"int" <<'\n';
}
void func(my m)
{
std::cout <<"my" <<'\n';
}
void func(your y)
{
std::cout <<"your" <<'\n';
}
int main()
{
func(1);
func(x);
func(y);
func(x+x); ///Ouch
my m = x;
my mm = static_cast<my>(x+x) ;// Ouch
int mmm = x+y; //ok
}
/*
output:
int
my
your
int
*/
regards
Andy Little
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk