diff options
author | James Player <james.w.player@gmail.com> | 2022-10-30 14:37:07 -0700 |
---|---|---|
committer | Kazu Hirata <kazu@google.com> | 2022-10-30 14:37:08 -0700 |
commit | bf738d2e77846826964402f2cccdd0681c71c038 (patch) | |
tree | d6620ce6224685e9b0b9030b6582411e6c4267d7 /llvm/unittests/Support/CommandLineTest.cpp | |
parent | d9f85656a641d94b1ff05bb40fa925ce35e7a21c (diff) | |
download | llvm-bf738d2e77846826964402f2cccdd0681c71c038.zip llvm-bf738d2e77846826964402f2cccdd0681c71c038.tar.gz llvm-bf738d2e77846826964402f2cccdd0681c71c038.tar.bz2 |
[ADT] Make mapped_iterator copy assignable
As mentioned in https://discourse.llvm.org/t/rfc-extend-ranges-infrastructure-to-better-match-c-20/65377
Lambda objects are not copy assignable, and therefore neither are
iterator types which hold a lambda. STL code require iterators be
copy assignable. Users may not use mapped_iterator with a std::deque
for example: https://godbolt.org/z/4Px7odEEd
This blog post [1] explains the problem and solution. We define a
wrapper class to store callable objects with two specialization.
1. Specialization for non-function types
- Use a std::optional as storage for non-function callable.
- Define operator=() implementation(s) which use
std::optional::emplace() instead of the assignment operator.
2. Specialization for function types
- Store as a pointer (even if template argument is a function reference).
- Default construct pointer to nullptr.
This Callable wrapper class is now default constructible (with invalid
state) and copy/move assignable.
With these new properties available on the callable object,
mapped_iterator can define a default constructor as well.
[1] https://www.fluentcpp.com/2019/04/16/an-alternative-design-to-iterators-and-ranges-using-stdoptional/
Reviewed By: kazu
Differential Revision: https://reviews.llvm.org/D134675
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
0 files changed, 0 insertions, 0 deletions