Skip to content

Commit

Permalink
add a project-wide .clang-format and reformat everything
Browse files Browse the repository at this point in the history
  • Loading branch information
ericniebler committed Feb 20, 2023
1 parent 2b288b8 commit 483f3eb
Show file tree
Hide file tree
Showing 145 changed files with 13,286 additions and 12,236 deletions.
139 changes: 139 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
Language: Cpp
BasedOnStyle: WebKit
AccessModifierOffset: -4
AlignAfterOpenBracket: AlwaysBreak
AlignArrayOfStructures: Right
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: None
AlignEscapedNewlines: DontAlign
AlignOperands: AlignAfterOperator
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
AttributeMacros: ['STDEXEC_DETAIL_CUDACC_HOST_DEVICE']
BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: Both
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakAfterJavaFieldAnnotations: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeConceptDeclarations: true
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
ColumnLimit: 100
CompactNamespaces: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: true
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: Leave
ExperimentalAutoDetectBinPacking: true
FixNamespaceComments: false
IncludeBlocks: Preserve
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentExternBlock: AfterExternBlock
IndentGotoLabels: false
IndentPPDirectives: None
IndentRequires: false
IndentWidth: 2
IndentWrappedFunctionNames: true
InsertTrailingCommas: None
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
PackConstructorInitializers: Never
PenaltyBreakAssignment: 64
PenaltyBreakBeforeFirstCallParameter: 64
PenaltyBreakComment: 512
PenaltyBreakFirstLessLess: 64
PenaltyBreakOpenParenthesis: 32
PenaltyBreakString: 64
PenaltyBreakTemplateDeclaration: 4
PenaltyExcessCharacter: 256
PenaltyIndentedWhitespace: 2
PenaltyReturnTypeOnItsOwnLine: 4
PointerAlignment: Left
QualifierAlignment: Leave
ReferenceAlignment: Pointer
RemoveBracesLLVM: false
ReflowComments: false
RequiresClausePosition: OwnLine
IndentRequiresClause: true
SeparateDefinitionBlocks: Always
ShortNamespaceLines: 0
SortIncludes: Never
SortUsingDeclarations: false
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceAroundPointerQualifiers: After
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: false
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: false
AfterFunctionDeclarationName: false
AfterFunctionDeclarationName: false
AfterFunctionDefinitionName: false
AfterIfMacros: false
AfterOverloadedOperator: false
AfterRequiresInClause: false
AfterRequiresInExpression: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: false
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Leave
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInParentheses: false
Standard: c++20
TabWidth: 0
UseCRLF: true
UseTab: Never
3 changes: 2 additions & 1 deletion examples/_clangd_helper_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
// than those in the parent (for example, if the subdirectory has a CMakeList.txt that defines additional executables).
// This ensures clangd provides useful intellisense for headers in any subdirectory with a CMakeList.txt.

int main(void) {}
int main(void) {
}
74 changes: 48 additions & 26 deletions examples/algorithms/retry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,39 @@ concept _decays_to = std::same_as<std::decay_t<From>, To>;

// _conv needed so we can emplace construct non-movable types into
// a std::optional.
template<std::invocable F>
template <std::invocable F>
requires std::is_nothrow_move_constructible_v<F>
struct _conv {
F f_;
explicit _conv(F f) noexcept : f_((F&&) f) {}

explicit _conv(F f) noexcept
: f_((F&&) f) {
}

operator std::invoke_result_t<F>() && {
return ((F&&) f_)();
}
};

template<class S, class R>
template <class S, class R>
struct _op;

// pass through all customizations except set_error, which retries the operation.
template<class S, class R>
struct _retry_receiver
: stdexec::receiver_adaptor<_retry_receiver<S, R>> {
template <class S, class R>
struct _retry_receiver : stdexec::receiver_adaptor<_retry_receiver<S, R>> {
_op<S, R>* o_;

R&& base() && noexcept { return (R&&) o_->r_; }
const R& base() const & noexcept { return o_->r_; }
R&& base() && noexcept {
return (R&&) o_->r_;
}

explicit _retry_receiver(_op<S, R>* o) : o_(o) {}
const R& base() const & noexcept {
return o_->r_;
}

explicit _retry_receiver(_op<S, R>* o)
: o_(o) {
}

template <class Error>
void set_error(Error&&) && noexcept {
Expand All @@ -62,62 +72,74 @@ struct _retry_receiver

// Hold the nested operation state in an optional so we can
// re-construct and re-start it if the operation fails.
template<class S, class R>
template <class S, class R>
struct _op {
S s_;
R r_;
std::optional<
stdexec::connect_result_t<S&, _retry_receiver<S, R>>> o_;
std::optional< stdexec::connect_result_t<S&, _retry_receiver<S, R>>> o_;

_op(S s, R r)
: s_((S&&) s)
, r_((R&&) r)
, o_{_connect()} {
}

_op(S s, R r): s_((S&&)s), r_((R&&)r), o_{_connect()} {}
_op(_op&&) = delete;

auto _connect() noexcept {
return _conv{[this] {
return stdexec::connect(s_, _retry_receiver<S, R>{this});
}};
}

void _retry() noexcept try {
o_.emplace(_connect()); // potentially throwing
stdexec::start(*o_);
} catch(...) {
} catch (...) {

stdexec::set_error((R&&) r_, std::current_exception());
}

friend void tag_invoke(stdexec::start_t, _op& o) noexcept {
stdexec::start(*o.o_);
}
};

template<class S>
template <class S>
struct _retry_sender {
using is_sender = void;
S s_;
explicit _retry_sender(S s) : s_((S&&) s) {}

template <class> using _error =
stdexec::completion_signatures<>;
template <class... Ts> using _value =
stdexec::completion_signatures<stdexec::set_value_t(Ts...)>;
explicit _retry_sender(S s)
: s_((S&&) s) {
}

template <class>
using _error = stdexec::completion_signatures<>;
template <class... Ts>
using _value = stdexec::completion_signatures<stdexec::set_value_t(Ts...)>;

template <class Env>
friend auto tag_invoke(stdexec::get_completion_signatures_t, const _retry_sender&, Env)
-> stdexec::make_completion_signatures<
S&, Env,
stdexec::completion_signatures<stdexec::set_error_t(std::exception_ptr)>,
_value, _error>;
S&,
Env,
stdexec::completion_signatures<stdexec::set_error_t(std::exception_ptr)>,
_value,
_error>;

template<stdexec::receiver R>
template <stdexec::receiver R>
friend _op<S, R> tag_invoke(stdexec::connect_t, _retry_sender&& self, R r) {
return {(S&&) self.s_, (R&&) r};
}

friend auto tag_invoke(stdexec::get_env_t, const _retry_sender& self)
friend auto tag_invoke(stdexec::get_env_t, const _retry_sender& self) //
noexcept(noexcept(stdexec::get_env(self.s_))) -> std::invoke_result_t<stdexec::get_env_t, S> {
return stdexec::get_env(self.s_);
}
};

template<stdexec::sender S>
template <stdexec::sender S>
stdexec::sender auto retry(S s) {
return _retry_sender{(S&&) s};
}
51 changes: 26 additions & 25 deletions examples/algorithms/then.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,34 +21,35 @@

///////////////////////////////////////////////////////////////////////////////
// then algorithm:
template<class R, class F>
class _then_receiver
: stdexec::receiver_adaptor<_then_receiver<R, F>, R> {
template <class R, class F>
class _then_receiver : stdexec::receiver_adaptor<_then_receiver<R, F>, R> {
friend stdexec::receiver_adaptor<_then_receiver, R>;
F f_;

template <class... As>
using _completions =
using _completions = //
stdexec::completion_signatures<
stdexec::set_value_t(std::invoke_result_t<F, As...>),
stdexec::set_error_t(std::exception_ptr)>;

// Customize set_value by invoking the callable and passing the result to the inner receiver
template<class... As>
template <class... As>
requires stdexec::receiver_of<R, _completions<As...>>
void set_value(As&&... as) && noexcept try {
stdexec::set_value(std::move(*this).base(), std::invoke((F&&) f_, (As&&) as...));
} catch(...) {
} catch (...) {

stdexec::set_error(std::move(*this).base(), std::current_exception());
}

public:
public:
_then_receiver(R r, F f)
: stdexec::receiver_adaptor<_then_receiver, R>{std::move(r)}
, f_(std::move(f)) {}
: stdexec::receiver_adaptor<_then_receiver, R>{std::move(r)}
, f_(std::move(f)) {
}
};

template<stdexec::sender S, class F>
template <stdexec::sender S, class F>
struct _then_sender {
using is_sender = void;

Expand All @@ -57,37 +58,37 @@ struct _then_sender {

// Compute the completion signatures
template <class... Args>
using _set_value_t =
stdexec::completion_signatures<
stdexec::set_value_t(std::invoke_result_t<F, Args...>)>;
using _set_value_t =
stdexec::completion_signatures< stdexec::set_value_t(std::invoke_result_t<F, Args...>)>;

template <class Env>
using _completions_t =
stdexec::make_completion_signatures<S, Env,
stdexec::completion_signatures<stdexec::set_error_t(std::exception_ptr)>,
_set_value_t>;
using _completions_t = //
stdexec::make_completion_signatures<
S,
Env,
stdexec::completion_signatures<stdexec::set_error_t(std::exception_ptr)>,
_set_value_t>;

template<class Env>
template <class Env>
friend auto tag_invoke(stdexec::get_completion_signatures_t, _then_sender&&, Env)
-> _completions_t<Env>;

// Connect:
template<class R>
//requires stdexec::receiver_of<R, _completions_t<stdexec::env_of_t<R>>>
//requires stdexec::receiver_of<R, stdexec::completion_signatures_of_t<S, stdexec::env_of_t<R>>>
template <class R>
//requires stdexec::receiver_of<R, _completions_t<stdexec::env_of_t<R>>>
//requires stdexec::receiver_of<R, stdexec::completion_signatures_of_t<S, stdexec::env_of_t<R>>>
friend auto tag_invoke(stdexec::connect_t, _then_sender&& self, R r)
-> stdexec::connect_result_t<S, _then_receiver<R, F>> {
return stdexec::connect(
(S&&) self.s_, _then_receiver<R, F>{(R&&) r, (F&&) self.f_});
return stdexec::connect((S&&) self.s_, _then_receiver<R, F>{(R&&) r, (F&&) self.f_});
}

friend auto tag_invoke(stdexec::get_env_t, const _then_sender& self)
friend auto tag_invoke(stdexec::get_env_t, const _then_sender& self) //
noexcept(noexcept(stdexec::get_env(self.s_))) -> std::invoke_result_t<stdexec::get_env_t, S> {
return stdexec::get_env(self.s_);
}
};

template<stdexec::sender S, class F>
template <stdexec::sender S, class F>
stdexec::sender auto then(S s, F f) {
return _then_sender<S, F>{(S&&) s, (F&&) f};
}
Loading

0 comments on commit 483f3eb

Please sign in to comment.