|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r62921 - sandbox/SOC/2010/bits_and_ints/boost/integer
From: muriloufg_at_[hidden]
Date: 2010-06-13 14:27:38
Author: murilov
Date: 2010-06-13 14:27:37 EDT (Sun, 13 Jun 2010)
New Revision: 62921
URL: http://svn.boost.org/trac/boost/changeset/62921
Log:
Removed modify_bit metafunction. Since we have set_bit and clear_bit we do not need that metafunction.
Added:
sandbox/SOC/2010/bits_and_ints/boost/integer/bit_utils.hpp (contents, props changed)
Added: sandbox/SOC/2010/bits_and_ints/boost/integer/bit_utils.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/bits_and_ints/boost/integer/bit_utils.hpp 2010-06-13 14:27:37 EDT (Sun, 13 Jun 2010)
@@ -0,0 +1,51 @@
+// Boost integer/bit_utils.hpp header file ------------------------------//
+
+// (C) Copyright Murilo Adriano Vasconcelos 2010.
+// 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 for updates, documentation, and revision history.
+
+#ifndef BOOST_BIT_UTILS_INCLUDED
+#define BOOST_BIT_UTILS_INCLUDED
+
+#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT
+
+/*
+ * Some utilities to handle integers.
+ */
+namespace boost
+{
+
+// Sets the bit `pos' in data
+template <typename T, T data, unsigned char pos>
+struct set_bit
+{
+ BOOST_STATIC_CONSTANT(T, value = data | (T(1) << pos));
+}; // set_bit
+
+// Clear the bit `pos' in data
+template <typename T, T data, unsigned char pos>
+struct clear_bit
+{
+ BOOST_STATIC_CONSTANT(T, value = data & ~(T(1) << pos));
+}; // clear_bit
+
+// If the bit `pos' is 1 then it will be 0 if not the bit will be 1
+template <typename T, T data, unsigned char pos>
+struct flip_bit
+{
+ BOOST_STATIC_CONSTANT(T, value = data ^ (T(1) << pos));
+}; // flip_bit
+
+// Test if the bit in `pos' positon is set or not
+template <typename T, T data, unsigned char pos>
+struct test_bit
+{
+ BOOST_STATIC_CONSTANT(bool, value = ((data >> pos) & T(1)) != T(0));
+}; // test_bit
+
+} // boost
+
+#endif
\ No newline at end of file
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