Skip to content

Commit

Permalink
Reapply "workarounds for clang again"
Browse files Browse the repository at this point in the history
This reverts commit be2b22d.
  • Loading branch information
wichtounet committed Jul 5, 2024
1 parent 54557ac commit e39af51
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
21 changes: 21 additions & 0 deletions include/views.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,16 @@ inline constexpr detail::not_template_adaptor not_template;
template <std::ranges::range R>
auto fold_left_auto(R&& r) {
using type = std::ranges::range_value_t<R>;
#ifdef __clang__
type value{};
for (const type & v : r) {
value += v;
}
return value;
#else
// On GCC; we can simply use fold left
return std::ranges::fold_left(std::forward<R>(r), type{}, std::plus<type>());
#endif
}

// TODO(C+23) In the future, we can simply ranges::to<std::vector> but it is not yet implemented with GCC
Expand Down Expand Up @@ -418,4 +427,16 @@ auto min_with_default(R&& r, std::ranges::range_value_t<R> def) {
return def;
}

// Stupid clang does not support std::ranges::contains

template <std::ranges::range R>
bool range_contains(const R& r, const std::ranges::range_value_t<R> & value) {
#ifdef __clang__
return std::ranges::find(std::ranges::begin(r), std::ranges::end(r), value) == std::ranges::end(r);
#else
// On GCC; we can simply use the algorithm
return std::ranges::contains(r, value);
#endif
}

} //end of namespace budget
2 changes: 1 addition & 1 deletion src/console_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ void budget::console_writer::display_table(std::vector<std::string>& columns, st

auto& row = contents[i];

const bool underline = std::ranges::contains(lines, i);
const bool underline = range_contains(lines, i);

for (size_t j = 0; j < row.size(); j += groups) {
size_t acc_width = 0;
Expand Down
8 changes: 8 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ unsigned short budget::terminal_height(){

std::vector<std::string>& budget::split(std::string_view s, char delim, std::vector<std::string>& elems) {
for (auto element : s | std::ranges::views::split(delim)) {
#ifdef __clang__
elems.emplace_back(std::string_view(&*element.begin(), std::ranges::distance(element)));
#else
elems.emplace_back(std::string_view(element));
#endif
}
return elems;
}
Expand All @@ -82,7 +86,11 @@ std::vector<std::string> budget::split(std::string_view s, char delim) {

std::vector<std::string_view>& budget::splitv(std::string_view s, char delim, std::vector<std::string_view>& elems) {
for (auto element : s | std::ranges::views::split(delim)) {
#ifdef __clang__
elems.emplace_back(std::string_view(&*element.begin(), std::ranges::distance(element)));
#else
elems.emplace_back(element);
#endif
}
return elems;
}
Expand Down

0 comments on commit e39af51

Please sign in to comment.