From d43657fbd561aed1ffeebda97b0139edaf17a92f Mon Sep 17 00:00:00 2001 From: Simon Brunel Date: Sat, 21 Mar 2020 14:23:40 +0100 Subject: [PATCH] Use clang-format for code style consistency Based on the WebKit preset and following 'most' of the Qt guidelines, except a few rules that work better for promise continuation lambdas. Requires clang-format 11. --- .clang-format | 66 +++++ src/qtpromise/qpromise.h | 91 +++---- src/qtpromise/qpromise.inl | 110 ++++---- src/qtpromise/qpromise_p.h | 238 ++++++++---------- src/qtpromise/qpromiseconnections.h | 8 +- src/qtpromise/qpromisefuture.h | 23 +- src/qtpromise/qpromiseglobal.h | 52 ++-- src/qtpromise/qpromisehelpers.h | 217 ++++++++-------- src/qtpromise/qpromisehelpers_p.h | 55 ++-- src/qtpromise/qpromiseresolver.h | 38 ++- .../qtpromise/benchmark/tst_benchmark.cpp | 185 ++++++++------ .../deprecations/tst_helpers_qpromise.cpp | 10 +- .../deprecations/tst_helpers_qpromiseall.cpp | 30 +-- .../deprecations/tst_qpromise_all.cpp | 30 +-- .../qtpromise/exceptions/tst_exceptions.cpp | 6 +- tests/auto/qtpromise/future/tst_future.cpp | 132 +++++----- tests/auto/qtpromise/helpers/tst_all.cpp | 30 +-- tests/auto/qtpromise/helpers/tst_attempt.cpp | 9 +- tests/auto/qtpromise/helpers/tst_each.cpp | 17 +- tests/auto/qtpromise/helpers/tst_filter.cpp | 17 +- tests/auto/qtpromise/helpers/tst_map.cpp | 15 +- tests/auto/qtpromise/helpers/tst_reduce.cpp | 127 ++++++---- tests/auto/qtpromise/helpers/tst_resolve.cpp | 12 +- tests/auto/qtpromise/internals/tst_argsof.cpp | 99 ++++++-- .../auto/qtpromise/qpromise/tst_construct.cpp | 55 ++-- tests/auto/qtpromise/qpromise/tst_each.cpp | 45 ++-- tests/auto/qtpromise/qpromise/tst_fail.cpp | 141 +++++++---- tests/auto/qtpromise/qpromise/tst_filter.cpp | 34 +-- tests/auto/qtpromise/qpromise/tst_finally.cpp | 4 +- tests/auto/qtpromise/qpromise/tst_map.cpp | 40 +-- .../auto/qtpromise/qpromise/tst_operators.cpp | 4 +- tests/auto/qtpromise/qpromise/tst_reduce.cpp | 120 +++++---- tests/auto/qtpromise/qpromise/tst_tap.cpp | 8 +- tests/auto/qtpromise/qpromise/tst_tapfail.cpp | 88 +++---- tests/auto/qtpromise/qpromise/tst_then.cpp | 119 +++++---- tests/auto/qtpromise/qpromise/tst_timeout.cpp | 92 +++---- .../requirements/tst_requirements.cpp | 187 +++++++++----- tests/auto/qtpromise/shared/data.h | 54 ++-- tests/auto/qtpromise/shared/utils.h | 55 ++-- tests/auto/qtpromise/thread/tst_thread.cpp | 94 ++++--- 40 files changed, 1534 insertions(+), 1223 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..0260e14 --- /dev/null +++ b/.clang-format @@ -0,0 +1,66 @@ +--- +Language: Cpp +Standard: Cpp11 +BasedOnStyle: WebKit +AlignAfterOpenBracket: true +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: false +AllowShortFunctionsOnASingleLine: Inline +AllowShortLambdasOnASingleLine: Empty +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterCaseLabel: false + AfterClass: true + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterStruct: true + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Custom +BreakInheritanceList: BeforeComma +BreakConstructorInitializers: BeforeColon +ColumnLimit: 100 +CommentPragmas: "^!|^:" +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +Cpp11BracedListStyle: true +FixNamespaceComments: true +ForEachMacros: + - BOOST_FOREACH + - foreach + - forever + - Q_FOREACH + - Q_FOREVER + - QBENCHMARK + - QBENCHMARK_ONCE +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^' + Priority: 2 + SortPriority: 0 + - Regex: '^<.*\.h>' + Priority: 3 + SortPriority: 0 + - Regex: '^<.*>' + Priority: 4 + SortPriority: 0 + - Regex: '.*' + Priority: 1 + SortPriority: 0 +IndentPPDirectives: AfterHash +NamespaceIndentation: None +PenaltyReturnTypeOnItsOwnLine: 10 +SpaceAfterTemplateKeyword: false +SpaceBeforeCpp11BracedList: false +... diff --git a/src/qtpromise/qpromise.h b/src/qtpromise/qpromise.h index 5c34ffd..6976b5d 100644 --- a/src/qtpromise/qpromise.h +++ b/src/qtpromise/qpromise.h @@ -19,27 +19,36 @@ namespace QtPromise { -template +template class QPromiseBase { public: using Type = T; - template ::count == 1, int>::type = 0> + template::count == 1, int>::type = 0> inline QPromiseBase(F resolver); - template ::count == 2, int>::type = 0> + template::count == 2, int>::type = 0> inline QPromiseBase(F resolver); - QPromiseBase(const QPromiseBase& other): m_d{other.m_d} {} - QPromiseBase(const QPromise& other): m_d{other.m_d} {} + QPromiseBase(const QPromiseBase& other) : m_d{other.m_d} { } + QPromiseBase(const QPromise& other) : m_d{other.m_d} { } QPromiseBase(QPromiseBase&& other) Q_DECL_NOEXCEPT { swap(other); } virtual ~QPromiseBase() { } - QPromiseBase& operator=(const QPromiseBase& other) { m_d = other.m_d; return *this;} + QPromiseBase& operator=(const QPromiseBase& other) + { + m_d = other.m_d; + return *this; + } QPromiseBase& operator=(QPromiseBase&& other) Q_DECL_NOEXCEPT - { QPromiseBase(std::move(other)).swap(*this); return *this; } + { + QPromiseBase(std::move(other)).swap(*this); + return *this; + } bool operator==(const QPromiseBase& other) const { return (m_d == other.m_d); } bool operator!=(const QPromiseBase& other) const { return (m_d != other.m_d); } @@ -50,31 +59,31 @@ public: bool isRejected() const { return m_d->isRejected(); } bool isPending() const { return m_d->isPending(); } - template + template inline typename QtPromisePrivate::PromiseHandler::Promise then(const TFulfilled& fulfilled, const TRejected& rejected) const; - template + template inline typename QtPromisePrivate::PromiseHandler::Promise then(TFulfilled&& fulfilled) const; - template + template inline typename QtPromisePrivate::PromiseHandler::Promise fail(TRejected&& rejected) const; - template + template inline QPromise finally(THandler handler) const; - template + template inline QPromise tap(THandler handler) const; - template + template inline QPromise tapFail(THandler handler) const; - template + template inline QPromise timeout(int msec, E&& error = E{}) const; - template + template inline QPromise timeout(std::chrono::milliseconds msec, E&& error = E{}) const; inline QPromise delay(int msec) const; @@ -83,7 +92,7 @@ public: inline QPromise wait() const; public: // STATIC - template + template inline static QPromise reject(E&& error); protected: @@ -94,39 +103,35 @@ protected: QExplicitlySharedDataPointer> m_d; }; -template +template class QPromise : public QPromiseBase { public: - template - QPromise(F&& resolver): QPromiseBase(std::forward(resolver)) { } + template + QPromise(F&& resolver) : QPromiseBase(std::forward(resolver)) + { } - template - inline QPromise - each(Functor fn); + template + inline QPromise each(Functor fn); - template - inline QPromise - filter(Functor fn); + template + inline QPromise filter(Functor fn); - template - inline typename QtPromisePrivate::PromiseMapper::PromiseType - map(Functor fn); + template + inline typename QtPromisePrivate::PromiseMapper::PromiseType map(Functor fn); - template - inline typename QtPromisePrivate::PromiseDeduce::Type - reduce(Functor fn, Input initial); + template + inline typename QtPromisePrivate::PromiseDeduce::Type reduce(Functor fn, Input initial); - template + template inline typename QtPromisePrivate::PromiseDeduce::Type reduce(Functor fn); public: // STATIC - // DEPRECATED (remove at version 1) - template