SOMHunter Core
common.h
Go to the documentation of this file.
1 /* This file is part of SOMHunter.
2  *
3  * Copyright (C) 2021 Frantisek Mejzlik <frankmejzlik@protonmail.com>
4  * Mirek Kratochvil <exa.exa@gmail.com>
5  * Patrik Vesely <prtrikvesely@gmail.com>
6  *
7  * SOMHunter is free software: you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License as published by the Free
9  * Software Foundation, either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * SOMHunter is distributed in the hope that it will be useful, but WITHOUT ANY
13  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * SOMHunter. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef COMMON_H_
22 #define COMMON_H_
23 
24 // Forward declare tester classes.
25 namespace sh {
26 namespace tests {
27 
28 class TESTER_Somhunter;
29 
30 }; // namespace tests
31 }; // namespace sh
32 
33 // *** CONFIGS ***
34 
35 #include "intrinsics.h"
36 #include "static-config.h"
37 
38 // *** TYPES ***
39 
40 #include "common-types.h"
41 #include "settings.h"
42 
43 // *** TOOLS ***
44 #include "static-logger.hpp"
45 
46 // helper type for the visitor #4
47 template <class... Ts>
48 struct overloaded : Ts... {
49  using Ts::operator()...;
50 };
51 
52 // explicit deduction guide (not needed as of C++20)
53 template <class... Ts>
54 overloaded(Ts...) -> overloaded<Ts...>;
55 
56 #include <string>
57 using namespace std::literals;
58 
64 template <typename NumericType>
65 struct ioterable {
66  using iterator_category = std::bidirectional_iterator_tag;
67  using value_type = NumericType;
68  using difference_type = NumericType;
69  using pointer = std::add_pointer_t<NumericType>;
70  using reference = NumericType;
71 
72  explicit ioterable(NumericType n) : val_(n) {}
73 
74  ioterable() = default;
75  ioterable(ioterable&&) = default;
76  ioterable(ioterable const&) = default;
77  ioterable& operator=(ioterable&&) = default;
78  ioterable& operator=(ioterable const&) = default;
79 
81  ++val_;
82  return *this;
83  }
85  ioterable tmp(*this);
86  ++val_;
87  return tmp;
88  }
89  bool operator==(ioterable const& other) const { return val_ == other.val_; }
90  bool operator!=(ioterable const& other) const { return val_ != other.val_; }
91 
92  value_type operator*() const { return val_; }
93 
94 private:
95  NumericType val_{ std::numeric_limits<NumericType>::max() };
96 };
97 
98 #endif // COMMON_H_
overloaded(Ts...) -> overloaded< Ts... >
Definition: common-types.h:33
Until C++20 and ranges come.
Definition: common.h:65
ioterable(NumericType n)
Definition: common.h:72
NumericType difference_type
Definition: common.h:68
bool operator==(ioterable const &other) const
Definition: common.h:89
NumericType reference
Definition: common.h:70
bool operator!=(ioterable const &other) const
Definition: common.h:90
ioterable & operator=(ioterable const &)=default
ioterable(ioterable &&)=default
NumericType val_
Definition: common.h:95
value_type operator*() const
Definition: common.h:92
ioterable(ioterable const &)=default
ioterable & operator=(ioterable &&)=default
ioterable()=default
std::bidirectional_iterator_tag iterator_category
Definition: common.h:66
ioterable operator++(int)
Definition: common.h:84
NumericType value_type
Definition: common.h:67
ioterable & operator++()
Definition: common.h:80
std::add_pointer_t< NumericType > pointer
Definition: common.h:69
Definition: common.h:48