Typesafe Integers and Bit Fields (enums) Description
DefinitionDefined in ExampleThe following is an example of code that will compile: // start_of_example #include <boost/detail/lightweight_test.hpp> #include <adobe/enum_ops.hpp> enum Foo { foo_4 = 1 << 2, foo_8 = 1 << 3 }; ADOBE_DEFINE_BITSET_OPS(Foo) int main() { Foo a(foo_4); Foo b(foo_8); Foo c(a | b); BOOST_TEST(a == 4L); BOOST_TEST(b == 8L); BOOST_TEST(c == 12L); return boost::report_errors(); } // end_of_example The following is contains an example of code that will not compile since the typesafe operators have not been defined. // start_of_example #include <boost/detail/lightweight_test.hpp> #include <adobe/enum_ops.hpp> enum Foo { foo_4 = 1 << 2, foo_8 = 1 << 3 }; enum Bar { bar_4 = 1 << 2, bar_8 = 1 << 3 }; enum Baz { baz_4 = 1 << 2, baz_8 = 1 << 3 }; ADOBE_DEFINE_ARITHMETIC_OPS(Baz) //ADOBE_DEFINE_ARITHMETIC_OPS is not defined for Foo and Bar int main() { Foo a(foo_4); Bar b(bar_8); Foo c(a + b); // error! a and b are different enum types, so result is integral Baz d(baz_4); Baz e(baz_8); Baz f(d + e); // Ok, ADOBE_DEFINE_ARITHMETIC_OPS(Baz) is defined, so d + e has type Baz BOOST_TEST(c); BOOST_TEST(f); return boost::report_errors(); } // end_of_example |