Skip to content

Commit eb9b335

Browse files
committed
more gcc workarounds
1 parent c0a8505 commit eb9b335

4 files changed

Lines changed: 82 additions & 10 deletions

File tree

include/rsl/_impl/format/fmt_parser.hpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
namespace rsl::_format_impl {
2020

2121
struct FormatResult {
22-
using join_t = std::string (FormatResult::*)(StyleMap const*) const;
23-
join_t join;
22+
using join_t = std::string (*)(StyleMap const*);
23+
join_t join = nullptr;
2424

2525
template <auto... Args>
26-
std::string join_impl(StyleMap const* style_map) const {
26+
static std::string join_impl(std::string_view raw, StyleMap const* style_map) {
2727
static constexpr Style::Tag style_tags[] = {Args...};
2828

2929
std::string result;
@@ -39,24 +39,32 @@ struct FormatResult {
3939
return result;
4040
}
4141

42+
template <auto... Args>
43+
constexpr static auto join_impl_ptr = &join_impl<Args...>;
44+
4245
FormatResult(std::string result, join_t joiner) : raw(std::move(result)), join(joiner) {}
4346

4447
std::string raw;
4548
[[nodiscard]] std::string with_style(StyleMap const& style) const {
46-
return (this->*join)(&style);
49+
return join(&style);
4750
}
48-
[[nodiscard]] std::string unstyled() const { return (this->*join)(nullptr); }
51+
[[nodiscard]] std::string unstyled() const { return join(nullptr); }
4952
[[nodiscard]] constexpr explicit(false) operator std::string() const { return unstyled(); }
5053
};
5154

52-
template <rsl::string_view fmt, typename Accessors, std::meta::info Joiner, typename... Args>
55+
56+
57+
template <rsl::string_view fmt, typename Accessors, /*auto Joiner,*/ typename... Args>
5358
FormatResult format_impl(Args&&... args) {
5459
auto str = [&]<typename... Xs>(AccessorList<Xs...>) {
5560
return std::format(fmt.data(), Xs::get(std::forward<Args...[Xs::index]>(args...[Xs::index]))...);
5661
}(Accessors{});
57-
return FormatResult(str, extract<FormatResult::join_t>(Joiner));
62+
return FormatResult(str, nullptr /*extract<FormatResult::join_t>(Joiner)*/);
5863
}
5964

65+
template <rsl::string_view fmt, typename Accessors, std::meta::info Joiner, typename... Args>
66+
constexpr auto format_impl_ptr = &format_impl<fmt, Accessors, /*Joiner,*/ Args...>;
67+
6068
struct FormatString {
6169
std::string string;
6270
std::vector<Style> style_tags;
@@ -75,10 +83,10 @@ struct FormatString {
7583
for (auto const& style : style_tags) {
7684
join_args.emplace_back(style);
7785
}
78-
args.push_back(reflect_constant(substitute(^^FormatResult::join_impl, join_args)));
86+
args.push_back(std::meta::reflect_constant(substitute(^^FormatResult::join_impl_ptr, join_args)));
7987

8088
(args.push_back(^^Args), ...);
81-
return extract<format_type<Args...>>(substitute(^^format_impl, args));
89+
return extract<format_type<Args...>>(substitute(^^format_impl_ptr, args));
8290
}
8391
};
8492

include/rsl/_impl/platform/io.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#if $os_is(LINUX)
55
# include <unistd.h>
6+
# include <sys/ioctl.h>
67
#elif $os_is(WINDOWS)
78
# define WIN32_LEAN_AND_MEAN
89
# include <windows.h>
@@ -31,4 +32,26 @@ inline bool isatty(int fd) {
3132
#endif
3233
}
3334

35+
struct TerminalDimensions {
36+
int rows;
37+
int columns;
38+
};
39+
40+
inline TerminalDimensions get_terminal_dimensions() {
41+
if (not isatty(STDOUT_FILENO)) {
42+
return {-1, -1};
43+
}
44+
#if $os_is(LINUX)
45+
struct winsize buffer;
46+
ioctl(STDOUT_FILENO, TIOCGWINSZ, &buffer);
47+
return {.rows = buffer.ws_row, .columns = buffer.ws_col};
48+
#elif $os_is(WINDOWS)
49+
CONSOLE_SCREEN_BUFFER_INFO csbi;
50+
51+
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
52+
return {.rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1,
53+
.columns = csbi.srWindow.Right - csbi.srWindow.Left + 1};
54+
#endif
55+
}
56+
3457
} // namespace rsl::_impl_platform

include/rsl/string_util

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#pragma once
2+
#include <string>
3+
#include <string_view>
4+
5+
#include <rsl/_impl/parser.hpp>
6+
7+
8+
namespace rsl {
9+
namespace _indent_impl {
10+
struct NonEmptyLine {
11+
static constexpr bool operator()(std::string_view line) {
12+
return std::ranges::any_of(line, [](char c){ return not rsl::_impl::is_whitespace(c); });
13+
}
14+
};
15+
}
16+
17+
constexpr std::string ltrim(std::string_view str) {
18+
return {str};
19+
}
20+
21+
constexpr std::string rtrim(std::string_view str) {
22+
return {str};
23+
}
24+
25+
constexpr std::string trim(std::string_view str) {
26+
return {str};
27+
}
28+
29+
constexpr std::string dedent(std::string_view str) {
30+
return {str};
31+
}
32+
33+
template <typename F = _indent_impl::NonEmptyLine>
34+
constexpr std::string indent(std::string_view str, std::string_view prefix, F&& condition = {}) {
35+
return {str};
36+
}
37+
38+
constexpr std::string reflow_text(std::string_view str, size_t columns = 80) {
39+
return {str};
40+
}
41+
} // namespace rsl

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ add_subdirectory(variant)
1212
add_subdirectory(tuple)
1313

1414
add_subdirectory(serializer)
15-
# add_subdirectory(trie)
15+
add_subdirectory(trie)

0 commit comments

Comments
 (0)