[libc++][ranges] Implement [special.mem.concepts].

Implement the exposition-only concepts specified in
`[special.mem.concepts]`. These are all thin wrappers over other
concepts.

Reviewed By: #libc, Quuxplusone, ldionne

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

NOKEYCHECK=True
GitOrigin-RevId: 2d9efcfeec2495e0e7da882d27f3ae0e261c3a24
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index ad08c66..df91edb 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -228,6 +228,7 @@
   __memory/allocator.h
   __memory/auto_ptr.h
   __memory/compressed_pair.h
+  __memory/concepts.h
   __memory/construct_at.h
   __memory/pointer_traits.h
   __memory/raw_storage_iterator.h
diff --git a/include/__memory/concepts.h b/include/__memory/concepts.h
new file mode 100644
index 0000000..4029b59
--- /dev/null
+++ b/include/__memory/concepts.h
@@ -0,0 +1,66 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___MEMORY_CONCEPTS_H
+#define _LIBCPP___MEMORY_CONCEPTS_H
+
+#include <__config>
+#include <__iterator/concepts.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/readable_traits.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <concepts>
+#include <type_traits>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if !defined(_LIBCPP_HAS_NO_RANGES)
+namespace ranges {
+
+// [special.mem.concepts]
+
+// This concept ensures that uninitialized algorithms can construct an object
+// at the address pointed-to by the iterator, which requires an lvalue.
+template <class _Ip>
+concept __nothrow_input_iterator =
+    input_iterator<_Ip> &&
+    is_lvalue_reference_v<iter_reference_t<_Ip>> &&
+    same_as<remove_cvref_t<iter_reference_t<_Ip>>, iter_value_t<_Ip>>;
+
+template <class _Sp, class _Ip>
+concept __nothrow_sentinel_for = sentinel_for<_Sp, _Ip>;
+
+template <class _Rp>
+concept __nothrow_input_range =
+    range<_Rp> &&
+    __nothrow_input_iterator<iterator_t<_Rp>> &&
+    __nothrow_sentinel_for<sentinel_t<_Rp>, iterator_t<_Rp>>;
+
+template <class _Ip>
+concept __nothrow_forward_iterator =
+    __nothrow_input_iterator<_Ip> &&
+    forward_iterator<_Ip> &&
+    __nothrow_sentinel_for<_Ip, _Ip>;
+
+template <class _Rp>
+concept __nothrow_forward_range =
+    __nothrow_input_range<_Rp> &&
+    __nothrow_forward_iterator<iterator_t<_Rp>>;
+
+} // namespace ranges
+#endif // !defined(_LIBCPP_HAS_NO_RANGES)
+
+_LIBCPP_END_NAMESPACE_STD
+
+#endif // _LIBCPP___MEMORY_CONCEPTS_H
diff --git a/include/memory b/include/memory
index f12f3c7..4d9dab5 100644
--- a/include/memory
+++ b/include/memory
@@ -669,6 +669,7 @@
 #include <__memory/allocator_arg_t.h>
 #include <__memory/allocator_traits.h>
 #include <__memory/compressed_pair.h>
+#include <__memory/concepts.h>
 #include <__memory/construct_at.h>
 #include <__memory/pointer_traits.h>
 #include <__memory/raw_storage_iterator.h>
diff --git a/include/module.modulemap b/include/module.modulemap
index a4a264b..25abdb0 100644
--- a/include/module.modulemap
+++ b/include/module.modulemap
@@ -630,21 +630,22 @@
     export *
 
     module __memory {
-      module addressof                { private header "__memory/addressof.h"                }
-      module allocation_guard         { private header "__memory/allocation_guard.h"         }
-      module allocator                { private header "__memory/allocator.h"                }
-      module allocator_arg_t          { private header "__memory/allocator_arg_t.h"          }
-      module allocator_traits         { private header "__memory/allocator_traits.h"         }
-      module auto_ptr                 { private header "__memory/auto_ptr.h"                 }
-      module compressed_pair          { private header "__memory/compressed_pair.h"          }
-      module construct_at             { private header "__memory/construct_at.h"             }
-      module pointer_traits           { private header "__memory/pointer_traits.h"           }
-      module raw_storage_iterator     { private header "__memory/raw_storage_iterator.h"     }
-      module shared_ptr               { private header "__memory/shared_ptr.h"               }
-      module temporary_buffer         { private header "__memory/temporary_buffer.h"         }
+      module addressof                { private header "__memory/addressof.h" }
+      module allocation_guard         { private header "__memory/allocation_guard.h" }
+      module allocator                { private header "__memory/allocator.h" }
+      module allocator_arg_t          { private header "__memory/allocator_arg_t.h" }
+      module allocator_traits         { private header "__memory/allocator_traits.h" }
+      module auto_ptr                 { private header "__memory/auto_ptr.h" }
+      module compressed_pair          { private header "__memory/compressed_pair.h" }
+      module concepts                 { private header "__memory/concepts.h" }
+      module construct_at             { private header "__memory/construct_at.h" }
+      module pointer_traits           { private header "__memory/pointer_traits.h" }
+      module raw_storage_iterator     { private header "__memory/raw_storage_iterator.h" }
+      module shared_ptr               { private header "__memory/shared_ptr.h" }
+      module temporary_buffer         { private header "__memory/temporary_buffer.h" }
       module uninitialized_algorithms { private header "__memory/uninitialized_algorithms.h" }
-      module unique_ptr               { private header "__memory/unique_ptr.h"               }
-      module uses_allocator           { private header "__memory/uses_allocator.h"           }
+      module unique_ptr               { private header "__memory/unique_ptr.h" }
+      module uses_allocator           { private header "__memory/uses_allocator.h" }
     }
   }
   module mutex {