1 /*-----------------------------------------------------------------------------+
2 Author: Joachim Faulhaber
3 Copyright (c) 2009-2009: Joachim Faulhaber
4 +------------------------------------------------------------------------------+
5 Distributed under the Boost Software License, Version 1.0.
6 (See accompanying file LICENCE.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 +-----------------------------------------------------------------------------*/
9 #ifndef BOOST_LIBS_ICL_EXAMPLE_LARGE_BITSET_BITS_HPP_JOFA_091019
10 #define BOOST_LIBS_ICL_EXAMPLE_LARGE_BITSET_BITS_HPP_JOFA_091019
12 // These includes are needed ...
13 #include <string> // for conversion to output and to
14 #include <boost/icl/type_traits/has_set_semantics.hpp>//declare that bits has the
20 //[mini_bits_class_bits
21 template<class NaturalT> class bits
24 typedef NaturalT word_type;
25 static const int digits = std::numeric_limits<NaturalT>::digits;
26 static const word_type w1 = static_cast<NaturalT>(1) ;
29 explicit bits(word_type value):_bits(value){}
31 word_type word()const{ return _bits; }
32 bits& operator |= (const bits& value){_bits |= value._bits; return *this;}
33 bits& operator &= (const bits& value){_bits &= value._bits; return *this;}
34 bits& operator ^= (const bits& value){_bits ^= value._bits; return *this;}
35 bits operator ~ ()const { return bits(~_bits); }
36 bool operator < (const bits& value)const{return _bits < value._bits;}
37 bool operator == (const bits& value)const{return _bits == value._bits;}
39 bool contains(word_type element)const{ return ((w1 << element) & _bits) != 0; }
40 std::string as_string(const char off_on[2] = " 1")const;
47 template<class NaturalT>
48 std::string bits<NaturalT>::as_string(const char off_on[2])const
51 for(int bit=0; bit < digits; bit++)
52 sequence += contains(bit) ? off_on[1] : off_on[0];
59 namespace boost { namespace icl
61 template<class NaturalT>
62 struct is_set<mini::bits<NaturalT> >
64 typedef is_set<mini::bits<NaturalT> > type;
65 BOOST_STATIC_CONSTANT(bool, value = true);
68 template<class NaturalT>
69 struct has_set_semantics<mini::bits<NaturalT> >
71 typedef has_set_semantics<mini::bits<NaturalT> > type;
72 BOOST_STATIC_CONSTANT(bool, value = true);