Skip to content

Commit 38c1a8f

Browse files
committed
Minor fixes
1 parent a32cde1 commit 38c1a8f

5 files changed

Lines changed: 33 additions & 18 deletions

File tree

include/GenericView.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,11 @@ class IteratorView {
129129
for (auto it = m_begin; it != m_end; ++it) { collector.append(*it); }
130130
return collector;
131131
}
132-
template <typename NewCont, Constructible<IteratorOutputType<Iter>> JoinObj>
133-
requires Pushable<NewCont, IteratorOutputType<Iter>>
132+
template <typename NewCont, Constructible<OutputType> JoinObj>
133+
requires Pushable<NewCont, OutputType>
134134
NewCont join_with(JoinObj obj) {
135-
using Ot = IteratorOutputType<Iter>;
136135
--m_end; // move end one before
137-
auto joiner = Ot{ Forward<JoinObj>(obj) };
136+
OutputType joiner{ Forward<JoinObj>(obj) };
138137
NewCont collector{};
139138
for (auto it = m_begin; it != m_end; ++it) {
140139
collector.append(*it);

include/Result.hpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ErrorBase {
1515
public:
1616
bool operator==(const ErrorBase& other) const { return error_string() == other.error_string(); }
1717
virtual StringView error_string() const = 0;
18-
virtual ~ErrorBase() = default;
18+
virtual ~ErrorBase() = default;
1919
};
2020
class Error : public ErrorBase {
2121
protected:
@@ -113,7 +113,6 @@ class Result {
113113
Result(OtherET&& val)
114114
requires(DerivedFrom<OtherET, ErrorBase>)
115115
: m_err{ new OtherET{ move(val) } }, m_type{ CurrType::Err } {}
116-
117116
// the following overloads may look very confusing
118117
// which is why they're commented
119118

@@ -126,7 +125,6 @@ class Result {
126125
Result(UniquePtr<OtherET>&& err) : m_type{ CurrType::Err } {
127126
new (&m_err) UniquePtr<ErrorBase>{ err.release() };
128127
}
129-
130128
// this overload activates when OtherET can be converted to ErrorType
131129
// *but* is not a derived type, this means that we don't care about object slicing
132130
// and we should instead just create a new error.
@@ -135,7 +133,6 @@ class Result {
135133
Result(UniquePtr<OtherET>&& err) : m_type{ CurrType::Err } {
136134
new (&m_err) UniquePtr<ErrorBase>{ new ErrorType{ move(*err) } };
137135
}
138-
139136
// this overload activates when OtherET is unrelated to ErrorType but the IntoError "interface"
140137
// can be used to convert from a type to the other
141138
template <typename OtherET>
@@ -295,9 +292,10 @@ class Result {
295292
}
296293
auto must() {
297294
if (is_error()) {
298-
ASSERT_NOT_REACHED_FMT(
299-
"%s::must() failed \"%s\"", TYPENAME_TO_STRING(*this), print_conditional(to_error()).data()
300-
);
295+
with_type_of(*this, [&](const char* name) {
296+
String error_name = print_conditional(to_error());
297+
ASSERT_NOT_REACHED_FMT("%s::must() failed \"%s\"", name, error_name.data());
298+
});
301299
}
302300
return to_ok();
303301
}
@@ -356,11 +354,9 @@ struct PrintInfo<Result<T, Err>> {
356354

357355
#define TRY_SET(val, expression) TRY_SET_IMPL(val, CONCAT_TOKENS(__tr_, __COUNTER__), expression)
358356

359-
#define TRY_RET(expression) \
360-
{ TRY_RET_IMPL(CONCAT_TOKENS(__tr_, __COUNTER__), expression) }
357+
#define TRY_RET(expression) { TRY_RET_IMPL(CONCAT_TOKENS(__tr_, __COUNTER__), expression) }
361358

362-
#define TRY(expression) \
363-
{ TRY_IMPL(CONCAT_TOKENS(__tr_, __COUNTER__), expression) }
359+
#define TRY(expression) { TRY_IMPL(CONCAT_TOKENS(__tr_, __COUNTER__), expression) }
364360

365361
#define MUST(expression) \
366362
[](auto&& tr) { \

include/String.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,14 @@ class String {
481481
char* buf = get_buf_internal();
482482
for (size_t i = 0; i < m_size; i++) { buf[i] = tolower(buf[i]); }
483483
}
484+
[[nodiscard]] String quoted(char quote_char = '"') const {
485+
String ret{};
486+
ret.reserve(size() + 2);
487+
ret.append(quote_char);
488+
ret.append(*this);
489+
ret.append(quote_char);
490+
return ret;
491+
}
484492
[[nodiscard]] String upper() const& {
485493
String str(*this);
486494
str.iupper();

include/TypeInfo.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ template <typename T>
2222
auto demangled_info_for() {
2323
return DemangledInfo{ typeid(T) };
2424
}
25+
26+
template <typename T,typename Func>
27+
void with_typename(Func&& func) {
28+
DemangledInfo info{ typeid(T) };
29+
func(info.name());
30+
}
31+
32+
template <typename T, typename Func>
33+
void with_type_of(T& value, Func&& func) {
34+
DemangledInfo info{ typeid(T) };
35+
func(info.name());
36+
}
37+
2538
} // namespace ARLib
2639
#define MANGLED_TYPENAME_TO_STRING(type) typeid(type).name()
2740

source/ArgParser.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,8 @@ ArgParser::ParseResult ArgParser::parse() {
186186
for (const auto& arg : m_arguments) { m_unmatched_arguments.append(String{ arg }); }
187187
if (m_unmatched_arguments.size() > m_leftover_args_needed) {
188188
String s{ "Argument parsing error: Unrecognized options found: " };
189-
for (const auto& unm : m_unmatched_arguments) { s += "\""_s + unm + "\", "_s; }
190-
s += '\n';
191-
return move(s);
189+
s += m_unmatched_arguments.iter().map([](auto&& o) { return o.quoted(); }).join_with<String>(", "_s);
190+
return s;
192191
}
193192
return DefaultOk{};
194193
}

0 commit comments

Comments
 (0)