Skip to content

Commit 40668b0

Browse files
committed
🎨 Fix clang-formatting
1 parent e8d9aa0 commit 40668b0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+3364
-4480
lines changed

include/safe.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#pragma once
22

3+
#include <safe/algorithm.hpp>
4+
#include <safe/array.hpp>
35
#include <safe/big_integer.hpp>
4-
#include <safe/var.hpp>
5-
#include <safe/dsl.hpp>
66
#include <safe/constant.hpp>
7-
#include <safe/value.hpp>
7+
#include <safe/dsl.hpp>
88
#include <safe/int.hpp>
9-
#include <safe/object.hpp>
109
#include <safe/match.hpp>
11-
#include <safe/algorithm.hpp>
12-
#include <safe/array.hpp>
10+
#include <safe/object.hpp>
11+
#include <safe/value.hpp>
12+
#include <safe/var.hpp>

include/safe/algorithm.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma once
22

3-
43
#include <safe/algorithm/accumulate.hpp>
54
#include <safe/algorithm/irange.hpp>
Lines changed: 68 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
#pragma once
22

3-
4-
#include <safe/var.hpp>
53
#include <safe/constant.hpp>
6-
#include <safe/dsl/eval.hpp>
7-
84
#include <safe/detail/concepts.hpp>
5+
#include <safe/dsl/eval.hpp>
6+
#include <safe/var.hpp>
97

108
#include <type_traits>
119
#include <utility>
1210

13-
1411
namespace safe {
15-
namespace detail {
16-
template<auto count>
17-
inline consteval auto fold(auto e, auto op){
18-
if constexpr (count > 100) {
12+
namespace detail {
13+
template <auto count> inline consteval auto fold(auto e, auto op) {
14+
if constexpr (count > 100) {
1915
return safe::dsl::detail::simp(
2016
op(op(op(op(op(op(op(op(op(op(
2117
op(op(op(op(op(op(op(op(op(op(
@@ -39,83 +35,76 @@ namespace safe {
3935
e), e), e), e), e), e), e), e), e), e)
4036
);
4137

42-
} else if constexpr (count > 10) {
43-
return safe::dsl::detail::simp(
44-
op(op(op(op(op(op(op(op(op(op(fold<count - 10>(e, op), e), e), e), e), e), e), e), e), e), e)
45-
);
46-
47-
} else if constexpr (count > 1) {
38+
} else if constexpr (count > 10) {
39+
return safe::dsl::detail::simp(op(
40+
op(op(op(op(op(op(op(op(op(fold<count - 10>(e, op), e), e),
41+
e),
42+
e),
43+
e),
44+
e),
45+
e),
46+
e),
47+
e),
48+
e));
49+
50+
} else if constexpr (count > 1) {
4851
return safe::dsl::detail::simp(op(fold<count - 1>(e, op), e));
4952

50-
} else {
53+
} else {
5154
return e;
52-
}
53-
}
54-
55-
inline constexpr auto plus_op = [](auto a, auto b){return a + b;};
5655
}
56+
}
5757

58+
constexpr inline auto plus_op = [](auto a, auto b) { return a + b; };
59+
} // namespace detail
5860

59-
template<size_t max_iter>
60-
[[nodiscard]] inline constexpr auto accumulate(
61-
detail::iter_like auto first,
62-
auto last,
63-
auto init,
64-
auto op
65-
) {
66-
constexpr auto req = decltype((*first).requirement){};
67-
constexpr auto sum_req = detail::fold<max_iter>(req, op);
61+
template <size_t max_iter>
62+
[[nodiscard]] constexpr inline auto accumulate(detail::iter_like auto first,
63+
auto last, auto init, auto op) {
64+
constexpr auto req = decltype((*first).requirement){};
65+
constexpr auto sum_req = detail::fold<max_iter>(req, op);
6866

69-
using ret_num_t = decltype((*first).unsafe_value());
67+
using ret_num_t = decltype((*first).unsafe_value());
7068

71-
auto iter_count = size_t{};
72-
auto sum = init;
73-
while ((first != last) && (iter_count < max_iter)) {
74-
sum = op(sum, (*first).unsafe_value());
75-
first++;
76-
iter_count++;
77-
}
78-
79-
return unsafe_cast<var<ret_num_t, sum_req>>(sum);
80-
}
81-
82-
template<size_t max_iter>
83-
[[nodiscard]] inline constexpr auto accumulate(
84-
detail::iter_like auto first,
85-
auto last,
86-
auto init
87-
) {
88-
return accumulate<max_iter>(first, last, init, detail::plus_op);
89-
}
90-
91-
template<size_t max_iter>
92-
[[nodiscard]] inline constexpr auto accumulate(
93-
detail::range_like auto & range,
94-
auto init,
95-
auto op
96-
) {
97-
return accumulate<max_iter>(range.begin(), range.end(), init, op);
69+
auto iter_count = size_t{};
70+
auto sum = init;
71+
while ((first != last) && (iter_count < max_iter)) {
72+
sum = op(sum, (*first).unsafe_value());
73+
first++;
74+
iter_count++;
9875
}
9976

100-
template<size_t max_iter>
101-
[[nodiscard]] inline constexpr auto accumulate(
102-
detail::range_like auto & range,
103-
auto init
104-
) {
105-
return accumulate<max_iter>(range.begin(), range.end(), init, detail::plus_op);
106-
}
107-
108-
template<size_t max_iter>
109-
[[nodiscard]] inline constexpr auto accumulate(
110-
detail::range_like auto const & range,
111-
auto init,
112-
auto op
113-
) {
114-
return accumulate<max_iter>(range.begin(), range.end(), init, op);
115-
}
116-
117-
template<size_t max_iter>
118-
[[nodiscard]] inline constexpr auto accumulate(auto const & range, auto init) {
119-
return accumulate<max_iter>(range.begin(), range.end(), init, detail::plus_op);
120-
}
121-
}
77+
return unsafe_cast<var<ret_num_t, sum_req>>(sum);
78+
}
79+
80+
template <size_t max_iter>
81+
[[nodiscard]] constexpr inline auto accumulate(detail::iter_like auto first,
82+
auto last, auto init) {
83+
return accumulate<max_iter>(first, last, init, detail::plus_op);
84+
}
85+
86+
template <size_t max_iter>
87+
[[nodiscard]] constexpr inline auto accumulate(detail::range_like auto &range,
88+
auto init, auto op) {
89+
return accumulate<max_iter>(range.begin(), range.end(), init, op);
90+
}
91+
92+
template <size_t max_iter>
93+
[[nodiscard]] constexpr inline auto accumulate(detail::range_like auto &range,
94+
auto init) {
95+
return accumulate<max_iter>(range.begin(), range.end(), init,
96+
detail::plus_op);
97+
}
98+
99+
template <size_t max_iter>
100+
[[nodiscard]] constexpr inline auto
101+
accumulate(detail::range_like auto const &range, auto init, auto op) {
102+
return accumulate<max_iter>(range.begin(), range.end(), init, op);
103+
}
104+
105+
template <size_t max_iter>
106+
[[nodiscard]] constexpr inline auto accumulate(auto const &range, auto init) {
107+
return accumulate<max_iter>(range.begin(), range.end(), init,
108+
detail::plus_op);
109+
}
110+
} // namespace safe

include/safe/algorithm/irange.hpp

Lines changed: 47 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,65 @@
11
#pragma once
22

3-
43
#include <safe/int.hpp>
54

6-
75
namespace safe {
8-
template<typename BeginT, typename EndT>
9-
struct irange {
10-
private:
11-
BeginT begin_;
12-
EndT end_;
13-
14-
template<typename T>
15-
struct iterator {
16-
private:
17-
irange const * parent_;
18-
T value_;
19-
bool end_;
6+
template <typename BeginT, typename EndT> struct irange {
7+
private:
8+
BeginT begin_;
9+
EndT end_;
2010

21-
public:
22-
using ret_t = decltype(clamp(0, parent_->begin_, parent_->end_ - s32_<1>));
11+
template <typename T> struct iterator {
12+
private:
13+
irange const *parent_;
14+
T value_;
15+
bool end_;
2316

24-
constexpr iterator(irange const * parent, T value, bool end)
25-
: parent_{parent}
26-
, value_{value}
27-
, end_{end}
28-
{}
17+
public:
18+
using ret_t =
19+
decltype(clamp(0, parent_->begin_, parent_->end_ - s32_<1>));
2920

30-
constexpr ret_t operator*() const {
31-
return unsafe_cast<ret_t>(value_);
32-
}
21+
constexpr iterator(irange const *parent, T value, bool end)
22+
: parent_{parent}, value_{value}, end_{end} {}
3323

34-
constexpr auto operator++() {
35-
auto const new_unsafe_value = value_++;
24+
constexpr ret_t operator*() const { return unsafe_cast<ret_t>(value_); }
3625

37-
// FIXME: consolidate range checks between == and ++
38-
if (new_unsafe_value < parent_->end_.unsafe_value()) {
39-
value_ = new_unsafe_value;
26+
constexpr auto operator++() {
27+
auto const new_unsafe_value = value_++;
4028

41-
} else {
42-
end_ = true;
43-
}
29+
// FIXME: consolidate range checks between == and ++
30+
if (new_unsafe_value < parent_->end_.unsafe_value()) {
31+
value_ = new_unsafe_value;
4432

45-
return *this;
33+
} else {
34+
end_ = true;
4635
}
4736

48-
constexpr bool operator==(iterator rhs) {
49-
if (end_) {
50-
return rhs.end_;
51-
52-
} else {
53-
return
54-
parent_ == rhs.parent_ &&
55-
value_ == rhs.value_ &&
56-
!rhs.end_;
57-
}
58-
}
59-
};
60-
61-
public:
62-
constexpr irange(
63-
BeginT begin,
64-
EndT end
65-
)
66-
: begin_{begin}
67-
, end_{end}
68-
{}
69-
70-
constexpr auto begin() const {
71-
return iterator<decltype(begin_.unsafe_value())>{this, begin_.unsafe_value(), begin_ == end_};
37+
return *this;
7238
}
7339

74-
constexpr auto end() const {
75-
// FIXME: need to find the right value for the end
76-
return iterator<decltype(begin_.unsafe_value())>{this, end_.unsafe_value() - 1, true};
40+
constexpr bool operator==(iterator rhs) {
41+
if (end_) {
42+
return rhs.end_;
43+
44+
} else {
45+
return parent_ == rhs.parent_ && value_ == rhs.value_ &&
46+
!rhs.end_;
47+
}
7748
}
7849
};
79-
}
50+
51+
public:
52+
constexpr irange(BeginT begin, EndT end) : begin_{begin}, end_{end} {}
53+
54+
constexpr auto begin() const {
55+
return iterator<decltype(begin_.unsafe_value())>{
56+
this, begin_.unsafe_value(), begin_ == end_};
57+
}
58+
59+
constexpr auto end() const {
60+
// FIXME: need to find the right value for the end
61+
return iterator<decltype(begin_.unsafe_value())>{
62+
this, end_.unsafe_value() - 1, true};
63+
}
64+
};
65+
} // namespace safe

0 commit comments

Comments
 (0)