Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70022 - sandbox/enums/libs/enums/example
From: vicente.botet_at_[hidden]
Date: 2011-03-16 16:21:20


Author: viboes
Date: 2011-03-16 16:21:18 EDT (Wed, 16 Mar 2011)
New Revision: 70022
URL: http://svn.boost.org/trac/boost/changeset/70022

Log:
Enums:Added some examples
Added:
   sandbox/enums/libs/enums/example/
   sandbox/enums/libs/enums/example/color_alert.cpp (contents, props changed)
   sandbox/enums/libs/enums/example/unsigned.cpp (contents, props changed)
   sandbox/enums/libs/enums/example/version.cpp (contents, props changed)

Added: sandbox/enums/libs/enums/example/color_alert.cpp
==============================================================================
--- (empty file)
+++ sandbox/enums/libs/enums/example/color_alert.cpp 2011-03-16 16:21:18 EDT (Wed, 16 Mar 2011)
@@ -0,0 +1,26 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2011.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/enums for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/enums/emulation.hpp>
+
+BOOST_ENUM_CLASS_START(Color, int)
+{ Red, Orange, Yellow, Green, Blue, Violet };
+BOOST_ENUM_CLASS_END(Color, int)
+BOOST_ENUMS_SPECIALIZATIONS(Color, int)
+
+BOOST_ENUM_CLASS_START(Alert, int)
+{ Green, Yellow, Red };
+BOOST_ENUM_CLASS_END(Alert, int)
+BOOST_ENUMS_SPECIALIZATIONS(Alert, int)
+
+void compile_fail() { Alert a = Alert::Green; bool armWeapons = ( a >= Color::Yellow ); }
+

Added: sandbox/enums/libs/enums/example/unsigned.cpp
==============================================================================
--- (empty file)
+++ sandbox/enums/libs/enums/example/unsigned.cpp 2011-03-16 16:21:18 EDT (Wed, 16 Mar 2011)
@@ -0,0 +1,29 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2011.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/enums for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/enums/emulation.hpp>
+#include <iostream>
+
+BOOST_ENUM_TYPE_START(E, unsigned long)
+{ E1 = 1, E2 = 2, Ebig = 0xFFFFFFF0U }
+BOOST_ENUM_TYPE_END(E, unsigned long)
+BOOST_ENUMS_SPECIALIZATIONS(E, unsigned long)
+
+
+int main() {
+ std::cout << sizeof( E ) << std::endl;
+ std::cout << "Ebig = " << E::Ebig << std::endl;
+ std::cout << "E1 ? -1 =\t" << ( E::E1 < -1 ? "less" : E::E1 > -1 ? "greater" : "equal" ) << std::endl;
+ std::cout << "Ebig ? -1 =\t" << ( E::Ebig < -1 ? "less" : E::Ebig > -1 ? "greater" : "equal" ) << std::endl;
+ return 0;
+}
+

Added: sandbox/enums/libs/enums/example/version.cpp
==============================================================================
--- (empty file)
+++ sandbox/enums/libs/enums/example/version.cpp 2011-03-16 16:21:18 EDT (Wed, 16 Mar 2011)
@@ -0,0 +1,26 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2011.
+// Distributed under the Boost
+// Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or
+// copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/enums for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/enums/emulation.hpp>
+#include <stdint.h>
+
+BOOST_ENUM_CLASS_START(Version, uint8_t)
+{ Ver1 = 1, Ver2 = 2 }
+BOOST_ENUM_CLASS_END(Version, uint8_t)
+BOOST_ENUMS_SPECIALIZATIONS(Version, uint8_t)
+
+struct Packet {
+ Version ver; // ok, portable
+ Version getVersion() const { return ver; }
+};
+
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk