Skip to content

Commit 1311cd4

Browse files
committed
Add some explicit return types
1 parent ae8aa8c commit 1311cd4

File tree

13 files changed

+57
-54
lines changed

13 files changed

+57
-54
lines changed

source/bounded/arithmetic/modulus.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ constexpr auto modulo_round = [](auto const dividend, umax_t const divisor) {
5858
);
5959
};
6060

61-
constexpr auto sign_free_value = [](auto const dividend, auto divisor) {
61+
constexpr auto sign_free_value = [](auto const dividend, auto divisor) -> min_max<umax_t, umax_t> {
6262
if (divisor.min > dividend.max) {
6363
return dividend;
6464
}

source/bounded/relocate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import std_module;
1414
namespace bounded_relocate_adl_detail {
1515

1616
template<typename T>
17-
constexpr auto relocate(T & ref) noexcept {
17+
constexpr auto relocate(T & ref) noexcept -> T {
1818
static_assert(std::is_nothrow_move_constructible_v<T>, "Please provide a noexcept relocate overload for your type or mark its move constructor noexcept.");
1919
static_assert(std::is_nothrow_destructible_v<T>, "Do not mark your destructor as noexcept(false)");
2020
auto result = std::move(ref);

source/bounded/to_integer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ constexpr auto as_digit(char const c) -> integer<0, 9> {
3434
}
3535

3636
template<auto maximum>
37-
constexpr auto to_integer_positive_impl(std::string_view const str) {
37+
constexpr auto to_integer_positive_impl(std::string_view const str) -> integer<0, normalize<maximum>> {
3838
auto positive_result = integer<0, normalize<maximum>>(0_bi);
3939
for (auto const c : str) {
4040
auto const shifted = positive_result * 10_bi;

source/containers/algorithms/accumulate.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ using accumulate_t = typename accumulate_c<Range, std::decay_t<Initial>, BinaryF
6161

6262

6363
export template<typename Result>
64-
constexpr auto accumulate(range auto && source, auto && initial, auto function) {
64+
constexpr auto accumulate(range auto && source, auto && initial, auto function) -> Result {
6565
auto result = static_cast<Result>(OPERATORS_FORWARD(initial));
6666
for (decltype(auto) value : OPERATORS_FORWARD(source)) {
6767
// Not ideal to have this `if` here
@@ -103,7 +103,7 @@ constexpr auto initial_product_value() {
103103
}
104104

105105
export template<typename Result>
106-
constexpr auto sum(range auto && source) {
106+
constexpr auto sum(range auto && source) -> Result {
107107
return ::containers::accumulate<Result>(
108108
OPERATORS_FORWARD(source),
109109
initial_sum_value<range_value_t<decltype(source)>>(),
@@ -120,7 +120,7 @@ export constexpr auto sum(range auto && source) {
120120
}
121121

122122
export template<typename Result>
123-
constexpr auto product(range auto && source) {
123+
constexpr auto product(range auto && source) -> Result {
124124
return ::containers::accumulate<Result>(
125125
OPERATORS_FORWARD(source),
126126
initial_product_value<range_value_t<decltype(source)>>(),

source/containers/algorithms/copy_or_relocate_from.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import containers.begin_end;
1313
import containers.can_set_size;
1414
import containers.dereference;
1515
import containers.is_container;
16+
import containers.iterator_t;
1617
import containers.range;
1718
import containers.range_value_t;
1819

@@ -23,7 +24,7 @@ using namespace bounded::literal;
2324

2425
namespace containers {
2526

26-
export constexpr auto copy_or_relocate_from = []<range Input>(Input && input, auto function) {
27+
export constexpr auto copy_or_relocate_from = []<range Input>(Input && input, auto function) -> iterator_t<Input> {
2728
// We do not relocate trivially copyable types because that requires setting
2829
// the size of the source range to 0. This is extra work that is not
2930
// necessary -- we don't want to make operations on rvalues more expensive

source/containers/algorithms/count.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ using namespace bounded::literal;
2020
namespace containers {
2121

2222
export template<range Range>
23-
constexpr auto count_if(Range && r, auto predicate) {
23+
constexpr auto count_if(Range && r, auto predicate) -> count_type<Range> {
2424
auto sum = count_type<Range>(0_bi);
2525
for (decltype(auto) value : OPERATORS_FORWARD(r)) {
2626
if (predicate(OPERATORS_FORWARD(value))) {

source/containers/algorithms/distance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace containers {
1717
using namespace bounded::literal;
1818

1919
export template<iterator InputIterator>
20-
constexpr auto distance(InputIterator first, sentinel_for<InputIterator> auto const last) {
20+
constexpr auto distance(InputIterator first, sentinel_for<InputIterator> auto const last) -> iter_difference_t<InputIterator> {
2121
if constexpr (requires { last - first; }) {
2222
return last - first;
2323
} else {

source/containers/algorithms/erase.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ using namespace bounded::literal;
3333
namespace containers {
3434

3535
export template<erasable Container>
36-
constexpr auto erase(Container & container, iterator_t<Container const &> const first, iterator_t<Container const &> const middle_) {
36+
constexpr auto erase(Container & container, iterator_t<Container const &> const first, iterator_t<Container const &> const middle_) -> iterator_t<Container &> {
3737
if constexpr (member_erasable<Container>) {
3838
return container.erase(first, middle_);
3939
} else if constexpr (splicable<Container>) {
4040
auto temp = Container();
4141
::containers::splice(temp, containers::begin(temp), container, first, middle_);
42-
return mutable_iterator(container, middle_);
42+
return ::containers::mutable_iterator(container, middle_);
4343
} else {
44-
auto const middle = ::containers::mutable_iterator(container, middle_);
45-
if (first == middle) {
46-
return middle;
44+
if (first == middle_) {
45+
return ::containers::mutable_iterator(container, middle_);
4746
}
47+
auto const middle = ::containers::mutable_iterator(container, middle_);
4848
auto const offset = first - containers::begin(container);
4949
auto const count = middle - first;
5050
auto const last = containers::end(container);
@@ -68,13 +68,13 @@ constexpr auto erase(Container & container, iterator_t<Container const &> const
6868
}
6969

7070
export template<erasable Container>
71-
constexpr auto erase(Container & container, iterator_t<Container const &> const it) {
71+
constexpr auto erase(Container & container, iterator_t<Container const &> const it) -> iterator_t<Container &> {
7272
BOUNDED_ASSERT(it != containers::end(container));
7373
return erase(container, it, ::containers::next(it));
7474
}
7575

7676
export template<erasable Container>
77-
constexpr void erase_to_end(Container & container, iterator_t<Container const &> const_position) {
77+
constexpr auto erase_to_end(Container & container, iterator_t<Container const &> const_position) -> void {
7878
auto const last = containers::end(container);
7979
if constexpr (can_set_size<Container>) {
8080
auto const count = last - const_position;
@@ -87,7 +87,7 @@ constexpr void erase_to_end(Container & container, iterator_t<Container const &>
8787
}
8888

8989
export template<erasable Container>
90-
constexpr auto erase_if(Container & container, auto predicate) {
90+
constexpr auto erase_if(Container & container, auto predicate) -> count_type<Container> {
9191
auto result = count_type<Container>(0_bi);
9292
if constexpr (constant_time_erasable<Container>) {
9393
for (auto it = containers::begin(container); it != containers::end(container); ) {
@@ -119,7 +119,7 @@ constexpr auto erase_if(Container & container, auto predicate) {
119119
}
120120

121121
export template<has_member_erase_after Container>
122-
constexpr void erase_after(Container & container, iterator_t<Container const &> const before_first, iterator_t<Container const &> const last) {
122+
constexpr auto erase_after(Container & container, iterator_t<Container const &> const before_first, iterator_t<Container const &> const last) -> void {
123123
auto it = containers::next(before_first);
124124
while (it != last) {
125125
it = container.erase_after(before_first);

source/containers/algorithms/find.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ using namespace bounded::literal;
2424
namespace containers {
2525

2626
export template<iterator Iterator>
27-
constexpr auto find_if(Iterator first, sentinel_for<Iterator> auto const last, auto predicate) {
27+
constexpr auto find_if(Iterator first, sentinel_for<Iterator> auto const last, auto predicate) -> Iterator {
2828
for (; first != last; ++first) {
2929
if (predicate(*first)) {
3030
break;
@@ -43,7 +43,7 @@ export constexpr auto find_if(range auto && range, auto predicate) {
4343

4444

4545
export template<bidirectional_iterator Iterator>
46-
constexpr auto find_last_if(Iterator const first, Iterator const last, auto predicate) {
46+
constexpr auto find_last_if(Iterator const first, Iterator const last, auto predicate) -> Iterator {
4747
for (auto it = last; it != first; ) {
4848
--it;
4949
if (predicate(*it)) {
@@ -63,7 +63,7 @@ export constexpr auto find_last_if(bidirectional_range auto && range, auto predi
6363

6464

6565
export template<iterator Iterator>
66-
constexpr auto find_if_not(Iterator first, sentinel_for<Iterator> auto const last, auto predicate) {
66+
constexpr auto find_if_not(Iterator first, sentinel_for<Iterator> auto const last, auto predicate) -> Iterator {
6767
return ::containers::find_if(std::move(first), last, std::not_fn(std::move(predicate)));
6868
}
6969

@@ -77,7 +77,7 @@ export constexpr auto find_if_not(range auto && range, auto predicate) {
7777

7878

7979
export template<bidirectional_iterator Iterator>
80-
constexpr auto find_last_if_not(Iterator const first, Iterator const last, auto predicate) {
80+
constexpr auto find_last_if_not(Iterator const first, Iterator const last, auto predicate) -> Iterator {
8181
return ::containers::find_last_if(first, last, std::not_fn(std::move(predicate)));
8282
}
8383

@@ -91,7 +91,7 @@ export constexpr auto find_last_if_not(bidirectional_range auto && range, auto p
9191

9292

9393
export template<iterator Iterator>
94-
constexpr auto find(Iterator first, sentinel_for<Iterator> auto const last, auto const & value) {
94+
constexpr auto find(Iterator first, sentinel_for<Iterator> auto const last, auto const & value) -> Iterator {
9595
return ::containers::find_if(std::move(first), last, bounded::equal_to(value));
9696
}
9797

@@ -105,7 +105,7 @@ export constexpr auto find(range auto && range, auto const & value) {
105105

106106

107107
export template<bidirectional_iterator Iterator>
108-
constexpr auto find_last(Iterator const first, Iterator const last, auto const & value) {
108+
constexpr auto find_last(Iterator const first, Iterator const last, auto const & value) -> Iterator {
109109
return ::containers::find_last_if(first, last, bounded::equal_to(value));
110110
}
111111

source/containers/algorithms/minmax_element.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export module containers.algorithms.minmax_element;
1212
import containers.algorithms.advance;
1313
import containers.array;
1414
import containers.begin_end;
15+
import containers.iterator_t;
1516
import containers.range;
1617

1718
import bounded;
@@ -21,7 +22,8 @@ namespace containers {
2122

2223
// TODO: minmax_element
2324

24-
export constexpr auto min_element(range auto && source, auto compare) {
25+
export template<range Range>
26+
constexpr auto min_element(Range && source, auto compare) -> iterator_t<Range> {
2527
auto smallest = containers::begin(OPERATORS_FORWARD(source));
2628
auto const last = containers::end(OPERATORS_FORWARD(source));
2729
if (smallest == last) {

0 commit comments

Comments
 (0)