Reapply "[libc++][ranges]Refactor `copy{,_backward}` and `move{,_backward}`"

This reverts commit a6e1080b87db8fbe0e1afadd96af5a3c0bd5e279.

Fix the conditions when the `memmove` optimization can be applied and refactor them out into a reusable type trait, fix and significantly expand the tests.

Differential Revision: https://reviews.llvm.org/D139235

NOKEYCHECK=True
GitOrigin-RevId: 5629d492df388bf6b5532a2a5c1ef5fd27d65ab0
diff --git a/include/valarray b/include/valarray
index 5b1f023..92521ed 100644
--- a/include/valarray
+++ b/include/valarray
@@ -4933,6 +4933,7 @@
 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
 #  include <algorithm>
 #  include <concepts>
+#  include <cstring>
 #  include <functional>
 #endif