Changeset 6804f38 for libcfa/src/enum.hfa
- Timestamp:
- Jul 17, 2024, 9:23:25 PM (4 weeks ago)
- Branches:
- master
- Children:
- c248b39, cd1d721, f90c092
- Parents:
- a758169
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/enum.hfa
ra758169 r6804f38 4 4 5 5 forall( E ) trait Bounded { 6 7 6 E lowerBound(); 7 E upperBound(); 8 8 }; 9 9 10 10 forall( E | Bounded( E ) ) trait Serial { 11 12 13 14 11 unsigned fromInstance( E e ); 12 E fromInt_unsafe( unsigned i ); 13 E succ_unsafe( E e ); 14 E pred_unsafe( E e ); 15 15 }; 16 16 17 17 forall( E | Serial( E ) ) { 18 19 20 21 18 E fromInt( unsigned i ); 19 E succ( E e ); 20 E pred( E e ); 21 int Countof( E e ); 22 22 } 23 23 24 24 // forall( E | Bounded(E) ) trait SafeSerial { 25 // 26 // 27 // 28 // 25 // // unsigned fromInstance( E e ); 26 // E fromInt_unsafe( unsigned i ); 27 // // E succ_unsafe( E e ); 28 // //E pred_unsafe( E e ); 29 29 30 // 31 // 32 // 33 // 30 // unsigned fromInstance( E e ); 31 // E fromInt( unsigned i ); 32 // E succ( E e ); 33 // E pred( E e ); 34 34 // }; 35 35 36 36 forall( E ) trait CfaEnum { 37 38 37 const char * label( E e ); 38 unsigned int posn( E e ); 39 39 }; 40 40 41 41 forall( E, V | CfaEnum( E ) ) trait TypedEnum { 42 42 V value( E e ); 43 43 }; 44 44 … … 55 55 static inline 56 56 forall( E | Serial(E) | CfaEnum(E) ) { 57 58 59 60 61 62 57 int ?==?( E l, E r ) { return posn( l ) == posn( r ); } // relational operators 58 int ?!=?( E l, E r ) { return posn( l ) != posn( r ); } 59 int ?<?( E l, E r ) { return posn( l ) < posn( r ); } 60 int ?<=?( E l, E r ) { return posn( l ) <= posn( r ); } 61 int ?>?( E l, E r ) { return posn( l ) > posn( r ); } 62 int ?>=?( E l, E r ) { return posn( l ) >= posn( r ); } 63 63 64 65 66 67 68 69 70 71 72 73 64 E ++?( E & l ) { // increment operators 65 l = succ( l ); 66 return l; 67 } 68 69 E ?++( E & l ) { 70 E ret = l; 71 l = succ( l ); 72 return ret; 73 } 74 74 75 76 77 78 75 E --?( E & l ) { 76 l = pred( l ); 77 return l; 78 } 79 79 80 81 82 83 84 80 E ?--( E & l ) { 81 E ret = l; 82 l = pred( l ); 83 return ret; 84 } 85 85 }
Note: See TracChangeset
for help on using the changeset viewer.