[libcxx-commits] [PATCH] D139235: Revert "Revert "[libc++][ranges]Refactor `copy{, _backward}` and `move{, _backward}`""

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Dec 14 11:08:31 PST 2022


ldionne added inline comments.


================
Comment at: libcxx/include/__type_traits/is_assignment_equivalent_to_bitcast.h:37-80
+  static const bool value = is_trivially_assignable<_To&, _From&>::value &&
+    // First, the simple case -- `From` and `To` are the same object type.
+    ((is_same<_UnqualFrom, _UnqualTo>::value && is_object<_UnqualFrom>::value) ||
+
+    // Beyond the simple case, we say that one type is "bit-cast assignable" to another if:
+    // - (1) `From` and `To` have the same value representation, and in addition every possible value of `From` has
+    //   a corresponding value in the `To` type (in other words, the set of values of `To` is a superset of the set of
----------------
```
// This is the trait for the core type property, separate from syntactic requirements
template <class _From, class _To> // those are cv-unqualified types always
struct __is_always_bitcastable {
  static constexpr bool value = 
     // basic case, only one type, check that it's trivially copyable
     (is_same< _From, _To >::value && is_trivially_copyable<_From>::value) ||
     (
       sizeof(_From) == sizeof(_To) &&
       is_integral<_From>::value &&
       is_integral<_To>::value &&
       !is_same<_To, bool>::value
     );
};

// Then inside std::copy, do:
enable_if_t<
  is_assignable<_From, _To>::value && __is_always_bitcastable<_From, _To>::value
>
It copy(...) {
  // use memcpy, which we know is valid since __is_always_bitcastable is true
}
```

That should also make the tests for this trait less weird, since now it will be natural that array types are always bitcastable, per the definition of trivially-copyable.


================
Comment at: libcxx/test/libcxx/type_traits/is_assignment_equivalent_to_bitcast.compile.pass.cpp:70-75
+constexpr void check_with_expected() {
+  meta::for_each(Types1{}, []<class T>() {
+    meta::for_each(Types2{}, []<class U>() {
+      check_with_cv<Expected, T, U>();
+    });
+  });
----------------
Let's inline this into `check` below? It's only used once.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139235



More information about the libcxx-commits mailing list