[libcxx-commits] [PATCH] D117736: [libc++][P2321R2] Add vector<bool>::reference::operator=(bool) const

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 31 10:37:54 PST 2022


Quuxplusone added a subscriber: BRevzin.
Quuxplusone added inline comments.


================
Comment at: libcxx/test/std/containers/sequences/vector.bool/reference/assign_bool.pass.cpp:38
+  assert(vec[0]);
+  assert(!vec[1]);
 
----------------
You'll need to either hide this under `TEST_STD_VER > 20` or remove the `_LIBCPP_STD_VER > 20` from `<__bit_reference>`. Honestly, I think removing it from `<__bit_reference>` might be the better way to go, for consistency's sake, but I'm prepared for that to be controversial. @ldionne thoughts? can we make `vector<bool>::iterator` indirectly writable in C++20/17/14/11/03 as well as 2b?


================
Comment at: libcxx/test/std/containers/sequences/vector.bool/reference/assign_bool.pass.cpp:41
   return true;
 }
 
----------------
It might be a good idea to add a more motivating test case in addition to this simple one. I'm thinking something like https://godbolt.org/z/T1f3rzejs , although it's still not crazy good as an example. I wonder if @BRevzin knows a better motivating example off the top of his head.
```
template<class T>
void test(T t) {
    std::vector<T> v = {t};
    const typename std::vector<T>::reference r = v[0];  // const-qualifying a reference type is a no-op
    r = t;  // therefore this should work consistently for T=int and T=bool
}
```
...Aha, you should also update `std/containers/sequences/vector.bool/iterator_concept_conformance.compile.pass.cpp` because this should now be true, not false!
```
    static_assert(std::indirectly_writable<std::vector<bool>::iterator, bool>);
```
That might be a sufficiently "motivating" example.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117736/new/

https://reviews.llvm.org/D117736



More information about the libcxx-commits mailing list