[libcxx-commits] [libcxx] [libc++] Add container_traits (prework for `std::flat_map`) (PR #109578)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Sep 27 10:36:31 PDT 2024


================
@@ -0,0 +1,173 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// <__type_traits/container_traits.h>
+//
+
+#include <__type_traits/container_traits.h>
+
+#include <deque>
+#include <forward_list>
+#include <list>
+#include <vector>
+#include <map>
+#include <set>
+#include <unordered_map>
+#include <unordered_set>
+
+#include "test_allocator.h"
+#include "test_macros.h"
+#include "MoveOnly.h"
+
+struct ThrowOnMove {
+  ThrowOnMove();
+  ThrowOnMove(const ThrowOnMove&) _NOEXCEPT_(false);
+  ThrowOnMove(ThrowOnMove&&) _NOEXCEPT_(false);
+  ThrowOnMove& operator=(ThrowOnMove&&) _NOEXCEPT_(false);
+  ThrowOnMove& operator=(const ThrowOnMove&) _NOEXCEPT_(false);
+
+  bool operator<(ThrowOnMove const&) const;
+  bool operator==(ThrowOnMove const&) const;
+};
+
+struct NonCopyThrowOnMove {
+  NonCopyThrowOnMove();
+  NonCopyThrowOnMove(ThrowOnMove&&) _NOEXCEPT_(false);
+  NonCopyThrowOnMove(const NonCopyThrowOnMove&) = delete;
+  NonCopyThrowOnMove& operator=(ThrowOnMove&&) _NOEXCEPT_(false);
+  NonCopyThrowOnMove& operator=(const NonCopyThrowOnMove&) = delete;
+
+  bool operator<(NonCopyThrowOnMove const&) const;
+  bool operator==(NonCopyThrowOnMove const&) const;
+};
+
+struct ThrowingHash {
+  template <class T>
+  std::size_t operator()(const T&) const _NOEXCEPT_(false);
+};
+
+struct NoThrowHash {
+  template <class T>
+  std::size_t operator()(const T&) const _NOEXCEPT;
+};
+
+template <class T, bool Expected>
+void test_emplacement_strong_exception() {
----------------
ldionne wrote:

Also I think the name of this function can be simplified to e.g. just `check` -- it doesn't add much value to make it more verbose.

https://github.com/llvm/llvm-project/pull/109578


More information about the libcxx-commits mailing list