Wordsearch Solver
dictionary_std_set.hpp
1 #ifndef DICTIONARY_STD_SET_HPP
2 #define DICTIONARY_STD_SET_HPP
3 
4 #include <cstddef>
5 #include <functional>
6 #include <initializer_list>
7 #include <ostream>
8 #include <set>
9 #include <string>
10 #include <string_view>
11 
13 namespace dictionary_std_set {
14 
21 public:
22  DictionaryStdSet() = default;
23 
25  DictionaryStdSet& operator=(DictionaryStdSet&&) = default;
26 
27  DictionaryStdSet(const DictionaryStdSet&) = delete;
28  DictionaryStdSet& operator=(const DictionaryStdSet&) = delete;
29 
30  DictionaryStdSet(const std::initializer_list<std::string_view>& words);
31  DictionaryStdSet(const std::initializer_list<std::string>& words);
32  DictionaryStdSet(const std::initializer_list<const char*>& words);
33 
39  template <
40  class Iterator1, class Iterator2,
41  std::enable_if_t<
42  std::is_same_v<typename std::iterator_traits<Iterator1>::value_type,
43  std::string_view>,
44  int> = 0>
45  DictionaryStdSet(Iterator1 first, const Iterator2 last);
46 
48  template <
49  class Iterator1, class Iterator2,
50  std::enable_if_t<
51  !std::is_same_v<typename std::iterator_traits<Iterator1>::value_type,
52  std::string_view>,
53  int> = 0>
54  DictionaryStdSet(Iterator1 first, const Iterator2 last);
55 
56  // TODO: awful SFINAE or wait until 2030 for widespread cpp20 concepts to
57  // constrain this to a ForwardRange
58  template <class ForwardRange>
59  explicit DictionaryStdSet(const ForwardRange& words);
60 
61  std::size_t size() const;
62  bool empty() const;
63 
65  template <class OutputIndexIterator>
66  void contains_further(const std::string_view stem,
67  const std::string_view suffixes,
68  OutputIndexIterator contains_further_it) const;
69 
71  bool contains(const std::string_view word) const;
73  bool further(const std::string_view word) const;
74 
75  friend std::ostream& operator<<(std::ostream&, const DictionaryStdSet&);
76 
77 private:
78  using Iterator = std::set<std::string>::const_iterator;
79 
84  std::set<std::string, std::less<void>> dict_;
85 };
86 
87 } // namespace dictionary_std_set
88 
89 #include "wordsearch_solver/dictionary_std_set/dictionary_std_set.tpp"
90 
91 #endif // DICTIONARY_STD_SET_HPP
Naive implementation that stores the dictionary in a std::set.
Definition: dictionary_std_set.hpp:20
bool contains(const std::string_view word) const
Check if this dictionary contains word.
Definition: dictionary_std_set.cpp:39
void contains_further(const std::string_view stem, const std::string_view suffixes, OutputIndexIterator contains_further_it) const
For each char in suffix appended to stem, check whether this dictionary contains this word and if it ...
Definition: dictionary_std_set.tpp:46
DictionaryStdSet(Iterator1 first, const Iterator2 last)
Constructor that does the work.
std::set< std::string, std::less< void > > dict_
Definition: dictionary_std_set.hpp:84
bool further(const std::string_view word) const
Check if this dictionary might contain words with word as a prefix.
Definition: dictionary_std_set.cpp:44
namespace dictionary_std_set
Definition: dictionary_std_set.hpp:13