Awali
Another Weighted Automata library
bitset.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_MISC_BITSET_HH
18 #define AWALI_MISC_BITSET_HH
19 
20 #include<bitset>
21 
22 namespace awali {
23  namespace sttc {
24  namespace internal {
25  template<size_t N>
26  struct bitset_iterator {
27  private:
28  const std::bitset<N>& bs_;
29  size_t current_ = 0u;
30  public:
31  bitset_iterator<N>(const std::bitset<N>& bs) : bs_(bs) {}
32 
33  bool has_next() {
34  while(current_ < N && !bs_.test(current_))
35  ++current_;
36  return (current_ < N);
37  }
38 
39  size_t next() {
40  while(current_ < N && !bs_.test(current_))
41  ++current_;
42  return current_++;
43  }
44 
45  };
46 
47  template<size_t N>
48  auto get_iterator(const std::bitset<N>& bs) -> bitset_iterator<N> {
49  return {bs};
50  }
51 
52  }
53  }
54 }//end of ns awali::stc
55 #endif
auto get_iterator(const std::bitset< N > &bs) -> bitset_iterator< N >
Definition: bitset.hh:48
Main namespace of Awali.
Definition: ato.hh:22
size_t next()
Definition: bitset.hh:39
bool has_next()
Definition: bitset.hh:33