Skip to content

Commit a0f6db3

Browse files
refactor: remove unneeded brackets
1 parent f52c06e commit a0f6db3

File tree

13 files changed

+29
-60
lines changed

13 files changed

+29
-60
lines changed

include/rusty_iterators/chain.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,13 @@ template <class T, class First, class Second>
3737
auto rusty_iterators::iterator::Chain<T, First, Second>::next() -> std::optional<T>
3838
{
3939
if (useSecond)
40-
{
4140
return second.next();
42-
}
41+
4342
auto nextItem = first.next();
4443

4544
if (nextItem.has_value())
46-
{
4745
return std::move(nextItem);
48-
}
46+
4947
useSecond = true;
5048
return next();
5149
}
@@ -58,8 +56,7 @@ auto rusty_iterators::iterator::Chain<T, First, Second>::sizeHint() const -> std
5856
auto sizeSecond = second.sizeHint();
5957

6058
if (!sizeFirst.has_value() || !sizeSecond.has_value())
61-
{
6259
return std::nullopt;
63-
}
60+
6461
return sizeFirst.value() + sizeSecond.value();
6562
}

include/rusty_iterators/cycle.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,8 @@ auto rusty_iterators::iterator::CopyCycle<T, Other>::sizeHint() const -> std::op
6666
auto size = it.sizeHint();
6767

6868
if (size.has_value() && size.value() > 0)
69-
{
7069
return std::nullopt;
71-
}
70+
7271
return 0;
7372
}
7473

@@ -88,10 +87,9 @@ auto rusty_iterators::iterator::CacheCycle<T, Other>::next() -> std::optional<T>
8887
if (!nextItem.has_value())
8988
{
9089
if (cache.size() == 0)
91-
{
9290
// If cycle is empty, we don't want to go into cached logic.
9391
return std::nullopt;
94-
}
92+
9593
useCache = true;
9694
return next();
9795
}
@@ -107,8 +105,7 @@ auto rusty_iterators::iterator::CacheCycle<T, Other>::sizeHint() const -> std::o
107105
auto size = it.sizeHint();
108106

109107
if (size.has_value() && size.value() > 0)
110-
{
111108
return std::nullopt;
112-
}
109+
113110
return 0;
114111
}

include/rusty_iterators/enumerate.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ auto rusty_iterators::iterator::Enumerate<T, Other>::next() -> std::optional<std
3737
auto nextItem = it.next();
3838

3939
if (!nextItem.has_value())
40-
{
4140
return std::nullopt;
42-
}
41+
4342
return std::tuple{idx++, std::move(nextItem.value())};
4443
}
4544

include/rusty_iterators/file_iterator.hpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,23 @@ class FileIterator<FIterType::Buffered>
2929
explicit FileIterator(const std::string& filePath, char delimiter = '\n')
3030
{
3131
std::ifstream is{filePath};
32+
3233
if (!is.is_open())
33-
{
3434
throw std::runtime_error{"Could not open the file."};
35-
}
35+
3636
std::string nextLine;
37+
3738
while (std::getline(is, nextLine, delimiter))
38-
{
3939
fileLines.push_back(std::move(nextLine));
40-
}
40+
4141
is.close();
4242
};
4343

4444
auto next() -> std::optional<std::string>
4545
{
4646
[[unlikely]] if (ptr == fileLines.size())
47-
{
4847
return std::nullopt;
49-
}
48+
5049
auto line = fileLines.at(ptr);
5150
ptr += 1;
5251
return std::move(line);
@@ -68,18 +67,16 @@ class FileIterator<FIterType::Lazy>
6867
: is(filePath), delimiter(delimiter)
6968
{
7069
if (!is.is_open())
71-
{
7270
throw std::runtime_error{"Could not open the file."};
73-
}
7471
};
7572

7673
auto next() -> std::optional<std::string>
7774
{
7875
std::string nextLine;
76+
7977
[[unlikely]] if (!std::getline(is, nextLine, delimiter))
80-
{
8178
return std::nullopt;
82-
}
79+
8380
return std::move(nextLine);
8481
}
8582

include/rusty_iterators/filter.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ auto rusty_iterators::iterator::Filter<T, Functor, Other>::next() -> std::option
3636
while (nextItem.has_value())
3737
{
3838
if (func(nextItem.value()))
39-
{
4039
return std::move(nextItem);
41-
}
40+
4241
nextItem = it.next();
4342
}
4443
return std::nullopt;

include/rusty_iterators/filter_map.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ auto rusty_iterators::iterator::FilterMap<Tin, Tout, Functor, Other>::next() ->
3939
auto result = func(std::move(nextItem.value()));
4040

4141
if (result.has_value())
42-
{
4342
return std::move(result.value());
44-
}
43+
4544
nextItem = it.next();
4645
}
4746
return std::nullopt;

include/rusty_iterators/interface.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,8 @@ auto rusty_iterators::interface::IterInterface<T, Derived>::position(Functor&& f
423423
[[likely]] while (nextItem.has_value())
424424
{
425425
if (func(nextItem.value()))
426-
{
427426
return position;
428-
}
427+
429428
position += 1;
430429
nextItem = self().next();
431430
}
@@ -440,9 +439,8 @@ auto rusty_iterators::interface::IterInterface<T, Derived>::reduce(Functor&& f)
440439
auto first = self().next();
441440

442441
[[unlikely]] if (!first.has_value())
443-
{
444442
return std::nullopt;
445-
}
443+
446444
return fold(std::move(first.value()), std::forward<Functor>(f));
447445
}
448446

@@ -482,9 +480,8 @@ auto rusty_iterators::interface::IterInterface<T, Derived>::tryFold(B&& init, Fu
482480
auto potentialAccum = func(std::move(accum), std::move(nextItem.value()));
483481

484482
if (potentialAccum.has_value())
485-
{
486483
return std::move(potentialAccum.value());
487-
}
484+
488485
accum = potentialAccum.error();
489486
nextItem = self().next();
490487
}
@@ -559,9 +556,8 @@ auto rusty_iterators::interface::IterInterface<T, Derived>::sizeHintChecked() ->
559556
auto size = self().sizeHint();
560557

561558
[[likely]] if (size.has_value())
562-
{
563559
return size.value();
564-
}
560+
565561
throw std::length_error{
566562
"Trying to collect an infinite iterator will result in an infinite loop."};
567563
}

include/rusty_iterators/iterator.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ template <class Container>
4747
auto rusty_iterators::iterator::LazyIterator<Container>::next() -> std::optional<T>
4848
{
4949
[[unlikely]] if (ptr == end)
50-
{
5150
return std::nullopt;
52-
}
5351

5452
auto& item = *ptr;
5553
ptr += 1;

include/rusty_iterators/map.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ auto rusty_iterators::iterator::Map<Tin, Functor, Other>::next() -> std::optiona
4444
auto item = it.next();
4545

4646
[[likely]] if (item.has_value())
47-
{
4847
return func(std::move(item.value()));
49-
}
48+
5049
return std::nullopt;
5150
}
5251

include/rusty_iterators/moving_window.hpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ class MovingWindow : public IterInterface<std::vector<T>, MovingWindow<T, Other>
1818
: it(std::forward<Other>(it)), orig(this->it), size(size)
1919
{
2020
if (size == 0)
21-
{
2221
throw std::length_error{"Moving window size must be greater that zero."};
23-
}
2422
}
2523

2624
auto next() -> std::optional<std::vector<T>>;
@@ -44,9 +42,8 @@ auto rusty_iterators::iterator::MovingWindow<T, Other>::next() -> std::optional<
4442
auto nextItem = it.next();
4543

4644
[[unlikely]] if (!nextItem.has_value())
47-
{
4845
return std::nullopt;
49-
}
46+
5047
result.push_back(std::move(nextItem.value()));
5148
}
5249

@@ -64,8 +61,7 @@ auto rusty_iterators::iterator::MovingWindow<T, Other>::sizeHint() const -> std:
6461
auto size = it.sizeHint();
6562

6663
if (!size.has_value())
67-
{
6864
return std::nullopt;
69-
}
65+
7066
return size.value() == 0 ? size : size.value() - 1;
7167
}

0 commit comments

Comments
 (0)