Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
bitset.hpp
Go to the documentation of this file.
1
6/*
7 * This file is part of Algorithms library toolkit.
8 * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
9
10 * Algorithms library toolkit is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14
15 * Algorithms library toolkit is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19
20 * You should have received a copy of the GNU General Public License
21 * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24#pragma once
25
26#include <ext/ostream>
27
28#include <bitset>
29#include <compare>
30
31namespace ext {
32
41template < std::size_t N >
42class bitset : public std::bitset < N > {
43public:
47 using std::bitset < N >::bitset; // NOLINT(modernize-use-equals-default)
48
52 using std::bitset < N >::operator =;
53#ifndef __clang__
54
58 bitset ( ) = default;
59
63 bitset ( const bitset & other ) = default;
64
68 bitset ( bitset && other ) = default;
69
73 bitset & operator = ( bitset && other ) = default;
74
78 bitset & operator = ( const bitset & other ) = default;
79#endif
80
81 std::strong_ordering operator <=> ( const ext::bitset < N > & second ) const {
82 const bitset < N > & first = * this;
83 for ( size_t i = 0; i < N; ++i ) {
84 std::strong_ordering res = first [ i ] <=> second [ i ];
85 if ( res != 0 )
86 return res;
87 }
88 return std::strong_ordering::equal;
89 }
90
91 bool operator == ( const ext::bitset < N > & second ) const {
92 return ( * this <=> second ) == 0;
93 }
94};
95
107template < size_t N >
109 out << "[";
110
111 for ( size_t i = 0; i < N; ++i ) {
112 if ( i != 0 ) out << ", ";
113 out << bitset [ i ];
114 }
115
116 out << "]";
117 return out;
118}
119
120} /* namespace ext */
Class extending the bitset class from the standard library. Original reason is to allow printing of t...
Definition: bitset.hpp:42
bitset()=default
std::strong_ordering operator<=>(const ext::bitset< N > &second) const
Definition: bitset.hpp:81
bitset(const bitset &other)=default
bitset(bitset &&other)=default
bitset & operator=(bitset &&other)=default
bool operator==(const ext::bitset< N > &second) const
Definition: bitset.hpp:91
Definition: ostream.h:14
p second
Definition: ToRegExpAlgebraic.h:126
int i
Definition: AllEpsilonClosure.h:118
return res
Definition: MinimizeByPartitioning.h:145
Definition: sigHandler.cpp:20
std::ostream & operator<<(ext::reference_wrapper< std::ostream > &os, std::ostream &(*const func)(std::ostream &))
Overloaded function allowing same operations on wrapped output stream as on the actual output stream,...
Definition: GlobalData.cpp:33