-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Add seqan3::copyable_wrapper #2963
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/seqan/seqan3/47y3BFmLSXaH92nNpcnVYwxE7eon |
Codecov Report
@@ Coverage Diff @@
## master #2963 +/- ##
=======================================
Coverage 98.19% 98.19%
=======================================
Files 267 268 +1
Lines 11521 11525 +4
=======================================
+ Hits 11313 11317 +4
Misses 208 208
Continue to review full report at Codecov.
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only questions. I don't know if I fully understood every change you made.
/*!\brief Helper concept for seqan3::copyable_wrapper. | ||
* \ingroup core | ||
* \see https://en.cppreference.com/w/cpp/ranges/copyable_wrapper | ||
* \noapi{Exposition only.} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why can't this be in seqan3::detail
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not because semiregular_box
wasn't...but because it's core
, we can just move it to detail, right?
Exposition only.
only refers to the standard, where it is considered as such. Won't matter if we move it to detail
Shall I move it into detail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed that in my former re-review.
IMHO, I would avoid "exposition only" mentions since we already have the detail namespace and the \noapi tag for stuff that we don't give guarantees for. Because this doesn't seem to be something we will expose to the user at any given point, I see no reason to NOT make it detail?
* This is a SeqAn-specific extension that allows easy invocation of the wrapped object. | ||
* `t` needs to be callable with the passed arguments. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give a short example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seqan3::copyable_wrapper wrapper{[] (int const x) { return x + 1; }};
auto wrapper_2 = wrapper; // A lambda function wouldn't be copyable.
wrapper(2); // Returns 3
wrapper_2(2); // Returns 3
It's a functionality that semiregular_box
had, but is not part of the Standard.
And we use it quite heavily, the alternative would be wrapper->operator()(2)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* This is a SeqAn-specific extension that allows easy invocation of the wrapped object. | |
* `t` needs to be callable with the passed arguments. | |
* | |
* This is a SeqAn-specific extension that allows easy invocation of the wrapped object. | |
* `t` needs to be callable with the passed arguments. | |
* e.g.: | |
* ``` | |
* seqan3::copyable_wrapper wrapper{[] (int const x) { return x + 1; }}; | |
* auto wrapper_2 = wrapper; // A lambda function wouldn't be copyable. | |
* wrapper(2); // Returns 3 | |
* wrapper_2(2); // Returns 3 | |
* ``` | |
* | |
since this is deep detail I'd be fine with no snippet but hard coded code |
* \see https://en.cppreference.com/w/cpp/ranges/copyable_wrapper | ||
* \details | ||
* | ||
* If `t` is `std::copyable`, the STL allows to only store `t`, i.e. no `std::optional` is needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* If `t` is `std::copyable`, the STL allows to only store `t`, i.e. no `std::optional` is needed. | |
* If `t` is `std::copyable`, the STL allows to store `t` directly, i.e. no `std::optional` is needed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will apply when applying other changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two doc issues but than it LGTM
* This is a SeqAn-specific extension that allows easy invocation of the wrapped object. | ||
* `t` needs to be callable with the passed arguments. | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* This is a SeqAn-specific extension that allows easy invocation of the wrapped object. | |
* `t` needs to be callable with the passed arguments. | |
* | |
* This is a SeqAn-specific extension that allows easy invocation of the wrapped object. | |
* `t` needs to be callable with the passed arguments. | |
* e.g.: | |
* ``` | |
* seqan3::copyable_wrapper wrapper{[] (int const x) { return x + 1; }}; | |
* auto wrapper_2 = wrapper; // A lambda function wouldn't be copyable. | |
* wrapper(2); // Returns 3 | |
* wrapper_2(2); // Returns 3 | |
* ``` | |
* | |
since this is deep detail I'd be fine with no snippet but hard coded code |
/*!\brief Helper concept for seqan3::copyable_wrapper. | ||
* \ingroup core | ||
* \see https://en.cppreference.com/w/cpp/ranges/copyable_wrapper | ||
* \noapi{Exposition only.} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed that in my former re-review.
IMHO, I would avoid "exposition only" mentions since we already have the detail namespace and the \noapi tag for stuff that we don't give guarantees for. Because this doesn't seem to be something we will expose to the user at any given point, I see no reason to NOT make it detail?
f09c6b7
to
6ccd4cf
Compare
@smehringer I did add a snippet. As it turns out, it's really, really hard to deliberately make a lambda non-copyable in cpp20. So, the example shows how to use |
This replaces
seqan3::semiregular_box
(implemented via range-v3) withseqan3::copyable_wrapper
(independent of range-v3).In early C++20 days, views were required to be default_initialisable (i.e.,
view{}
).For views that store a lambda, like
filter
ortransform
, this meant that the lambda would need to be default_constructible. To do this,semiregular_box
provided a wrapper that made any typesemiregular
(copyable + default_constructible).After some amendments to C++20, views are conditionally default_constructible (it is not a requirement anymore). Hence, we only need to make a lambda
copyable
->copyable_wrapper
.However, this change only applies starting with GCC12, for earlier versions, we still need semiregular (
SEQAN3_WORKAROUND_DEFAULT_CONSTRUCTIBLE_VIEW
takes care of this).There are two specialisations:
std::optional
with some extras to model copyableNote:
SEQAN3_WORKAROUND_DEFAULT_CONSTRUCTIBLE_VIEW
enables another check for 2. We can only use 2 with gcc<12 iff the underlying type is default_constructible. Otherwise, we need to fall back to 1 -std::optional
offers default_constructible.References: