Skip to content

Commit

Permalink
Update clang-format config (#29)
Browse files Browse the repository at this point in the history
This changes a few things from the Google defaults that I am not a fan
of, and generally makes the style more rigid.

This is going to wreck all kinds of blame, so I hope I don't decide to
do this again...
  • Loading branch information
mcy authored Jul 22, 2024
1 parent 8d4180b commit fdd77e7
Show file tree
Hide file tree
Showing 97 changed files with 2,216 additions and 2,522 deletions.
20 changes: 19 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
BasedOnStyle: Google
IndentWidth: 2

ColumnLimit: 80
IndentWidth: 2
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2

AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
InsertBraces: true

IndentRequiresClause: false
PointerAlignment: Left
QualifierAlignment: Custom
QualifierOrder: [inline, static, constexpr, friend, type]
RequiresClausePosition: WithPreceding

SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
AfterRequiresInClause: true
2 changes: 1 addition & 1 deletion best/base/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class vptr;
// because it's not defined yet. However, if it's a dependent type, we can delay
// it to the second phase of two-phase lookup.
template <best::is_object T, best::option<best::dependent<size_t, T>> =
best::option<best::dependent<size_t, T>>{}>
best::option<best::dependent<size_t, T>>{}>
class span;

// best/meta/empty.h
Expand Down
4 changes: 1 addition & 3 deletions best/base/hint.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ BEST_INLINE_ALWAYS constexpr void assume(bool truth) {
///
/// Hides a value from the compiler's optimizer.
[[nodiscard]] BEST_INLINE_SYNTHETIC constexpr auto&& black_box(auto&& value) {
if (!std::is_constant_evaluated()) {
asm volatile("" ::"m,r"(value));
}
if (!std::is_constant_evaluated()) { asm volatile("" ::"m,r"(value)); }
return decltype(value)(value);
}
} // namespace best
Expand Down
72 changes: 36 additions & 36 deletions best/base/internal/ord.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ template <typename T>
T common_ord(T);
template <typename T>
auto common_ord(T, T, auto... rest) //
-> decltype(common_ord(best::lie<T>, rest...));
-> decltype(common_ord(best::lie<T>, rest...));

sord common_ord(eq);
sord common_ord(le);
Expand All @@ -86,77 +86,77 @@ pord common_ord(uo, gt);
pord common_ord(uo, uo);

auto common_ord(sord, eq, auto... rest) //
-> decltype(common_ord(sord::equivalent, rest...));
-> decltype(common_ord(sord::equivalent, rest...));
auto common_ord(sord, le, auto... rest) //
-> decltype(common_ord(sord::equivalent, rest...));
-> decltype(common_ord(sord::equivalent, rest...));
auto common_ord(sord, gt, auto... rest) //
-> decltype(common_ord(sord::equivalent, rest...));
-> decltype(common_ord(sord::equivalent, rest...));
auto common_ord(eq, sord, auto... rest) //
-> decltype(common_ord(sord::equivalent, rest...));
-> decltype(common_ord(sord::equivalent, rest...));
auto common_ord(le, sord, auto... rest) //
-> decltype(common_ord(sord::equivalent, rest...));
-> decltype(common_ord(sord::equivalent, rest...));
auto common_ord(gt, sord, auto... rest) //
-> decltype(common_ord(sord::equivalent, rest...));
-> decltype(common_ord(sord::equivalent, rest...));

auto common_ord(word, eq, auto... rest) //
-> decltype(common_ord(word::equivalent, rest...));
-> decltype(common_ord(word::equivalent, rest...));
auto common_ord(word, le, auto... rest) //
-> decltype(common_ord(word::equivalent, rest...));
-> decltype(common_ord(word::equivalent, rest...));
auto common_ord(word, gt, auto... rest) //
-> decltype(common_ord(word::equivalent, rest...));
-> decltype(common_ord(word::equivalent, rest...));
auto common_ord(eq, word, auto... rest) //
-> decltype(common_ord(word::equivalent, rest...));
-> decltype(common_ord(word::equivalent, rest...));
auto common_ord(le, word, auto... rest) //
-> decltype(common_ord(word::equivalent, rest...));
-> decltype(common_ord(word::equivalent, rest...));
auto common_ord(gt, word, auto... rest) //
-> decltype(common_ord(word::equivalent, rest...));
-> decltype(common_ord(word::equivalent, rest...));

auto common_ord(pord, eq, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));
auto common_ord(pord, le, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));
auto common_ord(pord, gt, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));
auto common_ord(eq, pord, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));
auto common_ord(le, pord, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));
auto common_ord(gt, pord, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));

auto common_ord(uo, sord, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));
auto common_ord(uo, word, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));
auto common_ord(uo, pord, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));
auto common_ord(sord, uo, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));
auto common_ord(word, uo, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));
auto common_ord(pord, uo, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));

auto common_ord(sord, sord, auto... rest) //
-> decltype(common_ord(sord::equivalent, rest...));
-> decltype(common_ord(sord::equivalent, rest...));
auto common_ord(sord, word, auto... rest) //
-> decltype(common_ord(word::equivalent, rest...));
-> decltype(common_ord(word::equivalent, rest...));
auto common_ord(sord, pord, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));

auto common_ord(word, sord, auto... rest) //
-> decltype(common_ord(word::equivalent, rest...));
-> decltype(common_ord(word::equivalent, rest...));
auto common_ord(word, word, auto... rest) //
-> decltype(common_ord(word::equivalent, rest...));
-> decltype(common_ord(word::equivalent, rest...));
auto common_ord(word, pord, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));

auto common_ord(pord, sord, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));
auto common_ord(pord, word, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));
auto common_ord(pord, pord, auto... rest) //
-> decltype(common_ord(pord::equivalent, rest...));
-> decltype(common_ord(pord::equivalent, rest...));

auto common_impl(best::rank<1>, auto... args) -> decltype(common_ord(args...));
void common_impl(best::rank<0>, auto...);
Expand All @@ -171,9 +171,9 @@ class chain final {

constexpr friend auto operator->*(auto lhs, chain&& rhs) {
using output =
common<decltype(lhs), decltype(best::call(BEST_FWD(rhs).cb_))>;
common<decltype(lhs), decltype(best::call(BEST_FWD(rhs).cb_))>;

if (!(lhs == 0)) return output(lhs);
if (!(lhs == 0)) { return output(lhs); }
return output(best::call(BEST_FWD(rhs).cb_));
}

Expand Down
4 changes: 2 additions & 2 deletions best/base/niche.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ struct niche final {};
/// Whether T is a type with a niche.
template <typename T>
concept has_niche =
best::is_ref<T> || (best::is_object<T> && best::constructible<T, niche> &&
best::equatable<T, best::niche>);
best::is_ref<T> || (best::is_object<T> && best::constructible<T, niche> &&
best::equatable<T, best::niche>);
} // namespace best

#endif // BEST_BASE_NICHE_H_
22 changes: 11 additions & 11 deletions best/base/ord.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ concept testable = best::converts_to<T, bool> && requires(T cond) {
/// types to be void, and does not require either to be self-comparable.
template <typename T, typename U = T>
concept equatable =
(best::is_void<T> && best::is_void<U>) || requires(const T& a, const U& b) {
{ a == b } -> best::testable;
{ b == a } -> best::testable;
{ a != b } -> best::testable;
{ b != a } -> best::testable;
};
(best::is_void<T> && best::is_void<U>) || requires(const T& a, const U& b) {
{ a == b } -> best::testable;
{ b == a } -> best::testable;
{ a != b } -> best::testable;
{ b != a } -> best::testable;
};

/// # `best::comparable`
///
Expand All @@ -98,11 +98,11 @@ concept equatable =
/// types to be void, and does not require either to be self-comparable.
template <typename T, typename U = T>
concept comparable =
(best::is_void<T> && best::is_void<U>) || requires(const T& a, const U& b) {
requires best::equatable<T, U>;
{ a <=> b } -> best::converts_to<decltype(a <=> b)>;
{ b <=> a } -> best::converts_to<decltype(b <=> a)>;
};
(best::is_void<T> && best::is_void<U>) || requires(const T& a, const U& b) {
requires best::equatable<T, U>;
{ a <=> b } -> best::converts_to<decltype(a <=> b)>;
{ b <=> a } -> best::converts_to<decltype(b <=> a)>;
};

/// # `best::order_type<T, U>`
///
Expand Down
4 changes: 2 additions & 2 deletions best/base/ord_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ best::test Eq = [](auto& t) {

best::test Chain = [](auto& t) {
t.expect_eq(
best::ord::equal->*best::or_cmp([] { return best::ord::greater; }),
best::ord::greater);
best::ord::equal->*best::or_cmp([] { return best::ord::greater; }),
best::ord::greater);
t.expect_eq(best::ord::less->*best::or_cmp([] { return best::ord::greater; }),
best::ord::less);
};
Expand Down
2 changes: 1 addition & 1 deletion best/base/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ inline constexpr bool is_debug() {
/// Like `BEST_ENABLE_IF()`, but merely requires `expr_` to be constexpr.
#define BEST_ENABLE_IF_CONSTEXPR(expr_) \
__attribute__(( \
enable_if(__builtin_constant_p(expr_), "expected a constexpr value")))
enable_if(__builtin_constant_p(expr_), "expected a constexpr value")))

#else
#define BEST_HAS_ENABLE_IF 0
Expand Down
8 changes: 4 additions & 4 deletions best/base/tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ struct ftadle final {};

namespace tags_internal_do_not_use {
struct ctad_guard;
#define BEST_CTAD_GUARD_(type_, Tag_) \
static_assert( \
::std::is_same_v<Tag_, ::best::tags_internal_do_not_use::ctad_guard>, \
"you may not instantiate " type_ " manually; please use CTAD instead")
#define BEST_CTAD_GUARD_(type_, Tag_) \
static_assert( \
::std::is_same_v<Tag_, ::best::tags_internal_do_not_use::ctad_guard>, \
"you may not instantiate " type_ " manually; please use CTAD instead")
} // namespace tags_internal_do_not_use
} // namespace best

Expand Down
10 changes: 5 additions & 5 deletions best/cli/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ void app::install() {
auto prev = global_main.exchange(this);
if (prev != nullptr) {
best::wtf(
"detected two distinct `best::app`s in the same binary, at {:?} and "
"{:?}",
prev->loc_, loc_);
"detected two distinct `best::app`s in the same binary, at {:?} and "
"{:?}",
prev->loc_, loc_);
}
}

best::pretext<wtf8> app::exe() {
if (real_argv.is_empty()) return "";
if (real_argv.is_empty()) { return ""; }
return real_argv[0];
}

best::span<const best::pretext<wtf8>> app::argv() {
if (real_argv.is_empty()) return {};
if (real_argv.is_empty()) { return {}; }
return real_argv[{.start = 1}];
}

Expand Down
72 changes: 36 additions & 36 deletions best/cli/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class app final {
using mark_format_header_as_used = best::formatter;

app(auto main, best::location loc, int (*shim)(uintptr_t))
: main_(reinterpret_cast<uintptr_t>(main)), shim_(shim), loc_(loc) {
: main_(reinterpret_cast<uintptr_t>(main)), shim_(shim), loc_(loc) {
install();
}

Expand All @@ -124,57 +124,57 @@ class app final {

namespace best {
inline app::app(void (*main)(), best::location loc)
: app(main, loc, [](uintptr_t vp) {
auto main = reinterpret_cast<void (*)()>(vp);
main();
return 0;
}) {}
: app(main, loc, [](uintptr_t vp) {
auto main = reinterpret_cast<void (*)()>(vp);
main();
return 0;
}) {}

inline app::app(int (*main)(), best::location loc)
: app(main, loc, [](uintptr_t vp) {
auto main = reinterpret_cast<int (*)()>(vp);
return main();
}) {}
: app(main, loc, [](uintptr_t vp) {
auto main = reinterpret_cast<int (*)()>(vp);
return main();
}) {}

template <typename T, typename E>
app::app(best::result<T, E> (*main)(), best::location loc)
: app(main, loc, [](uintptr_t vp) {
auto main = reinterpret_cast<best::result<T, E> (*)()>(vp);
(void)*main();
return 0;
}) {}
: app(main, loc, [](uintptr_t vp) {
auto main = reinterpret_cast<best::result<T, E> (*)()>(vp);
(void)*main();
return 0;
}) {}

template <typename Args>
app::app(void (*main)(Args&), best::location loc)
: app(main, loc, [](uintptr_t vp) {
auto args = best::parse_flags<Args>(exe(), argv());
if (!args) args.err()->print_and_exit();
: app(main, loc, [](uintptr_t vp) {
auto args = best::parse_flags<Args>(exe(), argv());
if (!args) { args.err()->print_and_exit(); }

auto main = reinterpret_cast<void (*)(Args&)>(vp);
main(*args);
return 0;
}) {}
auto main = reinterpret_cast<void (*)(Args&)>(vp);
main(*args);
return 0;
}) {}

template <typename Args>
app::app(int (*main)(Args&), best::location loc)
: app(main, loc, [](uintptr_t vp) {
auto args = best::parse_flags<Args>(exe(), argv());
if (!args) args.err()->print_and_exit();
: app(main, loc, [](uintptr_t vp) {
auto args = best::parse_flags<Args>(exe(), argv());
if (!args) { args.err()->print_and_exit(); }

auto main = reinterpret_cast<int (*)(Args&)>(vp);
return main(*args);
}) {}
auto main = reinterpret_cast<int (*)(Args&)>(vp);
return main(*args);
}) {}

template <typename Args, typename T, typename E>
app::app(best::result<T, E> (*main)(Args&), best::location loc)
: app(main, loc, [](uintptr_t vp) {
auto args = best::parse_flags<Args>(exe(), argv());
if (!args) args.err()->print_and_exit();

auto main = reinterpret_cast<best::result<T, E> (*)(Args&)>(vp);
(void)*main(*args);
return 0;
}) {}
: app(main, loc, [](uintptr_t vp) {
auto args = best::parse_flags<Args>(exe(), argv());
if (!args) { args.err()->print_and_exit(); }

auto main = reinterpret_cast<best::result<T, E> (*)(Args&)>(vp);
(void)*main(*args);
return 0;
}) {}
} // namespace best

#endif // BEST_CLI_APP_H_
Loading

0 comments on commit fdd77e7

Please sign in to comment.