Skip to content

Commit 620775e

Browse files
committed
Run pre-commit on the files to format them.
1 parent e854abf commit 620775e

File tree

7 files changed

+85
-84
lines changed

7 files changed

+85
-84
lines changed

examples/filter_int_iterator.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
// filtered_int_iterator uses iterator_interface to define a forward iterator
1414
// that iterates over a sequence of integers, skipping those that do not satisfy a predicate.
1515
template <typename Pred>
16-
struct filtered_int_iterator
17-
: beman::iterator_interface::ext_iterator_interface_compat<filtered_int_iterator<Pred>,
18-
std::forward_iterator_tag,
19-
int> {
16+
struct filtered_int_iterator : beman::iterator_interface::ext_iterator_interface_compat<filtered_int_iterator<Pred>,
17+
std::forward_iterator_tag,
18+
int> {
2019
// Default constructor creates an end-of-range iterator.
2120
filtered_int_iterator() : m_it_begin(nullptr) {}
2221

2322
// Constructor for the beginning of the sequence.
24-
filtered_int_iterator(int* it_begin, int* it_end, Pred pred) : m_it_begin(it_begin), m_it_end(it_end), m_pred(std::move(pred)) {
23+
filtered_int_iterator(int* it_begin, int* it_end, Pred pred)
24+
: m_it_begin(it_begin), m_it_end(it_end), m_pred(std::move(pred)) {
2525
m_it_begin = std::find_if(m_it_begin, m_it_end, m_pred);
2626
}
2727

@@ -58,11 +58,11 @@ struct filtered_int_iterator
5858
int main() {
5959
// Create a filtered_int_iterator that iterates over the sequence {1, 2, 3, 4, 10, 11, 101, 200, 0},
6060
// skipping odd numbers. 0 is not skipped, so it will be the last element in the sequence.
61-
std::array a = {1, 2, 3, 4, 10, 11, 101, 200, 0};
61+
std::array a = {1, 2, 3, 4, 10, 11, 101, 200, 0};
6262
filtered_int_iterator it{std::begin(a), std::end(a), [](int i) { return i % 2 == 0; }};
63-
64-
while (*it) { // Expected output at STDOUT:
65-
std::cout << *it << " "; // 2 4 10 200 0
63+
64+
while (*it) { // Expected output at STDOUT:
65+
std::cout << *it << " "; // 2 4 10 200 0
6666
++it;
6767
}
6868
std::cout << "\n";

examples/repeated_chars_iterator.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,27 @@
1414
// repeated_chars_iterator uses iterator_interface to define a random access iterator
1515
// that iterates over a sequence of characters repeated indefinitely.
1616
class repeated_chars_iterator
17-
: public beman::iterator_interface::ext_iterator_interface_compat<repeated_chars_iterator,
18-
std::random_access_iterator_tag,
19-
char,
20-
char> {
21-
public:
17+
: public beman::iterator_interface::
18+
ext_iterator_interface_compat<repeated_chars_iterator, std::random_access_iterator_tag, char, char> {
19+
public:
2220
// Default constructor creates an end-of-range iterator.
2321
constexpr repeated_chars_iterator() : m_it_begin(nullptr), m_fixed_size(0), m_pos(0) {}
24-
22+
2523
// Constructor for the beginning of the sequence.
2624
constexpr repeated_chars_iterator(const char* it_begin, difference_type size, difference_type n)
2725
: m_it_begin(it_begin), m_fixed_size(size), m_pos(n) {}
2826

2927
// Random access iterator requirements:
30-
constexpr auto operator*() const { return m_it_begin[m_pos % m_fixed_size]; }
28+
constexpr auto operator*() const { return m_it_begin[m_pos % m_fixed_size]; }
3129
constexpr repeated_chars_iterator& operator+=(std::ptrdiff_t i) {
3230
m_pos += i;
3331
return *this;
3432
}
3533
constexpr auto operator-(repeated_chars_iterator other) const { return m_pos - other.m_pos; }
3634

37-
private:
35+
private:
3836
// Start of the sequence of characters.
39-
const char* m_it_begin;
37+
const char* m_it_begin;
4038

4139
// Number of characters in the sequence.
4240
difference_type m_fixed_size;
@@ -49,17 +47,18 @@ int main() {
4947
// Create a repeated_chars_iterator that iterates over the sequence "foo" repeated indefinitely:
5048
// "foofoofoofoofoofoo...". Will actually extract a prefix of the sequence and insert it into a std::string.
5149
constexpr const std::string_view target = "foo";
52-
constexpr const auto len = 7; // Number of extracted characters from the sequence.
50+
constexpr const auto len = 7; // Number of extracted characters from the sequence.
5351

5452
// Create iterators that go over the sequence "foofoofoofoofoofoo...".
55-
repeated_chars_iterator it_first(target.data(), target.size(), 0); // target.size() == 3 is the length of "foo", 0 is this iterator's position.
56-
repeated_chars_iterator it_last(target.data(), target.size(), len); // Same as above, but now the iterator's position is 7.
53+
repeated_chars_iterator it_first(
54+
target.data(), target.size(), 0); // target.size() == 3 is the length of "foo", 0 is this iterator's position.
55+
repeated_chars_iterator it_last(
56+
target.data(), target.size(), len); // Same as above, but now the iterator's position is 7.
5757

5858
std::string extracted_result;
5959
std::copy(it_first, it_last, std::back_inserter(extracted_result));
6060
assert(extracted_result.size() == len);
61-
std::cout << extracted_result << "\n"; // Expected output at STDOUT: "foofoof"
61+
std::cout << extracted_result << "\n"; // Expected output at STDOUT: "foofoof"
6262

6363
return 0;
6464
}
65-

include/beman/iterator_interface/detail/stl_interfaces/config.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@
3232
// multiple vI namespace alternatives exist. For example, some instances of
3333
// the v1 namespace may still be inline, if there is no v2 version of its
3434
// contents.
35-
#if !BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_USE_CONCEPTS && !BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_USE_DEDUCED_THIS
35+
#if !BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_USE_CONCEPTS && \
36+
!BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_USE_DEDUCED_THIS
3637
#define BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_NAMESPACE_V1 inline namespace v1
3738
#define BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_NAMESPACE_V2 namespace v2
3839
#define BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_NAMESPACE_V3 namespace v3
39-
#elif BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_USE_CONCEPTS && !BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_USE_DEDUCED_THIS
40+
#elif BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_USE_CONCEPTS && \
41+
!BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_USE_DEDUCED_THIS
4042
#define BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_NAMESPACE_V1 namespace v1
4143
#define BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_NAMESPACE_V2 inline namespace v2
4244
#define BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_NAMESPACE_V3 namespace v3

include/beman/iterator_interface/detail/stl_interfaces/iterator_interface.hpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ namespace stl_interfaces {
2828
this template implies a copy or move of the underlying object of type
2929
`T`. */
3030
template <typename T>
31-
#if defined(BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_DOXYGEN) || BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_USE_CONCEPTS
31+
#if defined(BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_DOXYGEN) || \
32+
BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_USE_CONCEPTS
3233
// clang-format off
3334
requires std::is_object_v<T>
3435
#endif
@@ -99,7 +100,9 @@ struct common_eq {
99100
};
100101
template <typename T, typename U>
101102
struct common_eq<T, U, true> {
102-
static constexpr auto call(T lhs, U rhs) { return iterator_interface_access::base(lhs) == iterator_interface_access::base(rhs); }
103+
static constexpr auto call(T lhs, U rhs) {
104+
return iterator_interface_access::base(lhs) == iterator_interface_access::base(rhs);
105+
}
103106
};
104107

105108
template <typename T, typename U>
@@ -213,7 +216,7 @@ BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_NAMESPACE_V1 {
213216
template <typename D = Derived>
214217
constexpr auto operator->() const
215218
noexcept(noexcept(detail::make_pointer<pointer, reference>(*std::declval<const D&>())))
216-
-> decltype(detail::make_pointer<pointer, reference>(*std::declval<const D&>())) {
219+
-> decltype(detail::make_pointer<pointer, reference>(*std::declval<const D&>())) {
217220
return detail::make_pointer<pointer, reference>(*derived());
218221
}
219222

@@ -249,7 +252,8 @@ BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_NAMESPACE_V1 {
249252
}
250253

251254
template <typename D = Derived>
252-
constexpr auto operator+=(difference_type n) noexcept(noexcept(iterator_interface_access::base(std::declval<D&>()) += n))
255+
constexpr auto
256+
operator+=(difference_type n) noexcept(noexcept(iterator_interface_access::base(std::declval<D&>()) += n))
253257
-> decltype(iterator_interface_access::base(std::declval<D&>()) += n, std::declval<D&>()) {
254258
iterator_interface_access::base(derived()) += n;
255259
return derived();
@@ -263,8 +267,8 @@ BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_NAMESPACE_V1 {
263267
retval += i;
264268
return retval;
265269
}
266-
friend BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_HIDDEN_FRIEND_CONSTEXPR Derived operator+(difference_type i,
267-
Derived it) noexcept {
270+
friend BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_HIDDEN_FRIEND_CONSTEXPR Derived
271+
operator+(difference_type i, Derived it) noexcept {
268272
return it + i;
269273
}
270274

@@ -299,8 +303,10 @@ BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_NAMESPACE_V1 {
299303

300304
template <typename D = Derived>
301305
constexpr auto operator-(D other) const
302-
noexcept(noexcept(iterator_interface_access::base(std::declval<const D&>()) - iterator_interface_access::base(other)))
303-
-> decltype(iterator_interface_access::base(std::declval<const D&>()) - iterator_interface_access::base(other)) {
306+
noexcept(noexcept(iterator_interface_access::base(std::declval<const D&>()) -
307+
iterator_interface_access::base(other)))
308+
-> decltype(iterator_interface_access::base(std::declval<const D&>()) -
309+
iterator_interface_access::base(other)) {
304310
return iterator_interface_access::base(derived()) - iterator_interface_access::base(other);
305311
}
306312

@@ -402,7 +408,8 @@ BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_NAMESPACE_V1 {
402408
} // namespace stl_interfaces
403409
} // namespace beman::iterator_interface::detail
404410

405-
#if defined(BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_DOXYGEN) || BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_USE_CONCEPTS
411+
#if defined(BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_DOXYGEN) || \
412+
BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_USE_CONCEPTS
406413

407414
namespace beman::iterator_interface::detail {
408415
namespace stl_interfaces {
@@ -727,7 +734,8 @@ BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_NAMESPACE_V2 {
727734

728735
#endif
729736

730-
#if defined(BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_DOXYGEN) || BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_USE_DEDUCED_THIS
737+
#if defined(BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_DOXYGEN) || \
738+
BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_USE_DEDUCED_THIS
731739

732740
namespace beman::iterator_interface::detail {
733741
namespace stl_interfaces {
@@ -954,15 +962,15 @@ BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_NAMESPACE_V3 {
954962
#define BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_STATIC_ASSERT_CONCEPT(iter, concept_name)
955963
#endif
956964

957-
#define BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_STATIC_ASSERT_ITERATOR_TRAITS_IMPL( \
965+
#define BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_STATIC_ASSERT_ITERATOR_TRAITS_IMPL( \
958966
iter, category, value_t, ref, ptr, diff_t) \
959967
static_assert(std::is_same<typename std::iterator_traits<iter>::value_type, value_t>::value, ""); \
960968
static_assert(std::is_same<typename std::iterator_traits<iter>::reference, ref>::value, ""); \
961969
static_assert(std::is_same<typename std::iterator_traits<iter>::pointer, ptr>::value, ""); \
962970
static_assert(std::is_same<typename std::iterator_traits<iter>::difference_type, diff_t>::value, "");
963971

964972
#define BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_STATIC_ASSERT_ITERATOR_TRAITS( \
965-
iter, category, concept, value_type, reference, pointer, difference_type) \
973+
iter, category, concept, value_type, reference, pointer, difference_type) \
966974
BEMAN_ITERATOR_INTERFACE_DETAIL_STL_INTERFACES_STATIC_ASSERT_ITERATOR_TRAITS_IMPL( \
967975
iter, category, value_type, reference, pointer, difference_type)
968976
#endif

include/beman/iterator_interface/iterator_interface.hpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,31 +142,27 @@ struct iter_cat<IteratorConcept, ReferenceType, false> {};
142142

143143
template <typename IteratorConcept, typename ReferenceType>
144144
struct iter_cat<IteratorConcept, ReferenceType, true> {
145-
using iterator_category =
146-
std::conditional_t<
147-
!std::is_reference_v<ReferenceType>,
148-
std::input_iterator_tag,
149-
std::conditional_t<
150-
std::is_base_of_v<std::random_access_iterator_tag, IteratorConcept>,
151-
std::random_access_iterator_tag,
152-
std::conditional_t<
153-
std::is_base_of_v<std::bidirectional_iterator_tag, IteratorConcept>,
154-
std::bidirectional_iterator_tag,
155-
std::forward_iterator_tag>>>;
145+
using iterator_category = std::conditional_t<
146+
!std::is_reference_v<ReferenceType>,
147+
std::input_iterator_tag,
148+
std::conditional_t<std::is_base_of_v<std::random_access_iterator_tag, IteratorConcept>,
149+
std::random_access_iterator_tag,
150+
std::conditional_t<std::is_base_of_v<std::bidirectional_iterator_tag, IteratorConcept>,
151+
std::bidirectional_iterator_tag,
152+
std::forward_iterator_tag>>>;
156153
};
157154

158155
} // namespace detail
159156

160157
template <class IteratorConcept, class ValueType, class Reference, class Pointer, class DifferenceType>
161158
class iterator_interface
162-
: detail::iter_cat<IteratorConcept, Reference, std::derived_from<IteratorConcept, std::forward_iterator_tag>>
163-
{
159+
: detail::iter_cat<IteratorConcept, Reference, std::derived_from<IteratorConcept, std::forward_iterator_tag>> {
164160
public:
165161
using iterator_concept = IteratorConcept;
166-
using value_type = remove_const_t<ValueType>;
167-
using reference = Reference;
168-
using pointer = conditional_t<is_same_v<iterator_concept, output_iterator_tag>, void, Pointer>;
169-
using difference_type = DifferenceType;
162+
using value_type = remove_const_t<ValueType>;
163+
using reference = Reference;
164+
using pointer = conditional_t<is_same_v<iterator_concept, output_iterator_tag>, void, Pointer>;
165+
using difference_type = DifferenceType;
170166

171167
constexpr decltype(auto) operator*(this auto&& self)
172168
requires requires { *iterator_interface_access::base(self); }

include/beman/iterator_interface/iterator_interface_access.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ struct iterator_interface_access {
2121
return d.base_reference();
2222
}
2323
};
24-
}
25-
}
24+
} // namespace iterator_interface
25+
} // namespace beman
2626
#endif

tests/beman/iterator_interface/iterator_interface.test.cpp

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,25 @@ TEST(IteratorTest, TestRepeatedChars) {
6060
TEST(IteratorTest, TestDistance) {
6161
auto lambda = [&] {
6262
repeated_chars_iterator first("foo", 3, 0); // 3 is the length of "foo", 0 is this iterator's position.
63-
repeated_chars_iterator last("foo", 3, 3); // 3 is the length of "foo", 3 is this iterator's position.
63+
repeated_chars_iterator last("foo", 3, 3); // 3 is the length of "foo", 3 is this iterator's position.
6464
std::string result;
6565
std::copy(first, last, std::back_inserter(result));
6666
CONSTEXPR_EXPECT_EQ(std::distance(first, last), 3);
6767
};
6868

6969
static_assert((lambda(), true));
70-
lambda();
70+
lambda();
7171
}
7272

7373
TEST(IteratorTest, TestNext) {
7474
auto lambda = [&] {
7575
repeated_chars_iterator first("foo", 3, 0); // 3 is the length of "foo", 0 is this iterator's position.
76-
repeated_chars_iterator last("foo", 3, 3); // 3 is the length of "foo", 3 is this iterator's position.
76+
repeated_chars_iterator last("foo", 3, 3); // 3 is the length of "foo", 3 is this iterator's position.
7777
CONSTEXPR_EXPECT_EQ(std::next(first, 3), last);
7878
};
7979

8080
static_assert((lambda(), true));
81-
lambda();
81+
lambda();
8282
}
8383

8484
TEST(IteratorTest, TestConcepts) {
@@ -174,30 +174,26 @@ TEST(IteratorTest, OperatorArrow) {
174174
ASSERT_EQ(ai->f(), 3);
175175
}
176176

177-
struct dummy_input_iterator :
178-
public ext_iterator_interface_compat<
179-
dummy_input_iterator, std::input_iterator_tag, int, int const&, void, std::ptrdiff_t> {
180-
constexpr dummy_input_iterator() { }
181-
dummy_input_iterator(dummy_input_iterator const&) = delete;
182-
dummy_input_iterator& operator=(dummy_input_iterator const&) = delete;
183-
dummy_input_iterator(dummy_input_iterator&&) = default;
184-
dummy_input_iterator& operator=(dummy_input_iterator&&) = default;
185-
constexpr reference operator*() const {
186-
return foo;
187-
}
188-
constexpr dummy_input_iterator& operator++() {
189-
return *this;
190-
}
191-
constexpr void operator++(int) {}
192-
193-
friend constexpr bool operator==(std::default_sentinel_t const&,
194-
dummy_input_iterator const&) {
195-
return true;
196-
}
197-
198-
friend beman::iterator_interface::iterator_interface_access;
199-
200-
int foo = 0;
177+
struct dummy_input_iterator : public ext_iterator_interface_compat<dummy_input_iterator,
178+
std::input_iterator_tag,
179+
int,
180+
const int&,
181+
void,
182+
std::ptrdiff_t> {
183+
constexpr dummy_input_iterator() {}
184+
dummy_input_iterator(const dummy_input_iterator&) = delete;
185+
dummy_input_iterator& operator=(const dummy_input_iterator&) = delete;
186+
dummy_input_iterator(dummy_input_iterator&&) = default;
187+
dummy_input_iterator& operator=(dummy_input_iterator&&) = default;
188+
constexpr reference operator*() const { return foo; }
189+
constexpr dummy_input_iterator& operator++() { return *this; }
190+
constexpr void operator++(int) {}
191+
192+
friend constexpr bool operator==(const std::default_sentinel_t&, const dummy_input_iterator&) { return true; }
193+
194+
friend beman::iterator_interface::iterator_interface_access;
195+
196+
int foo = 0;
201197
};
202198

203199
static_assert(std::input_iterator<dummy_input_iterator>);

0 commit comments

Comments
 (0)