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
diff --git a/libcxx/include/algorithm b/libcxx/include/algorithm
index 69cdc14..cb2d27c 100644
--- a/libcxx/include/algorithm
+++ b/libcxx/include/algorithm
@@ -1707,7 +1707,6 @@
 #include <__config>
 #include <__debug>
 #include <cstddef>
-#include <cstring>
 #include <type_traits>
 #include <version>
 
@@ -1917,6 +1916,7 @@
 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
 #  include <atomic>
 #  include <concepts>
+#  include <cstring>
 #  include <iterator>
 #  include <memory>
 #  include <stdexcept>