[libcxx-commits] [libcxx] [libc++] P2165R4: Update deduction guides for map containers and container adaptors (PR #136011)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Apr 19 12:14:20 PDT 2025
================
@@ -0,0 +1,123 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+#include <array>
+#include <flat_map>
+#include <iostream>
+#include <map>
+#include <set>
+#include <string>
+#include <tuple>
+#include <type_traits>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+#include "test_macros.h"
+
+int main(int, char**) {
+ #if TEST_STD_VER >= 23
+ // --- Input Data ---
+ // 1. Vector of std::pair
+ std::vector<std::pair<const int, std::string>> pair_vec = {{1, "apple"}, {2, "banana"}, {3, "cherry"}};
+
+ // 2. Vector of std::tuple
+ std::vector<std::tuple<int, double>> tuple_vec = {{10, 1.1}, {20, 2.2}, {30, 3.3}};
+
+ // 3. Vector of std::array
+ std::vector<std::array<long, 2>> array_vec = {{100L, 101L}, {200L, 201L}, {300L, 301L}};
+
+ // 4. Vector of std::pair with non-const key (for testing const addition in iter_to_alloc_type)
+ std::vector<std::pair<int, std::string>> non_const_key_pair_vec = {{5, "grape"}, {6, "kiwi"}};
+
+
+ // --- CTAD Tests ---
+
+ // map
+ std::map m1(pair_vec.begin(), pair_vec.end());
+ static_assert(std::is_same_v<decltype(m1), std::map<int, std::string>>);
----------------
KSARK wrote:
I initially tried to find an existing test file where these deduction guide checks (covering `map`, `unordered_map`, `flat_map`, etc.) would fit naturally. Since none seemed quite right for such broad associative container tests, creating a dedicated file in `associative.general` seemed like the cleanest solution.
https://github.com/llvm/llvm-project/pull/136011
More information about the libcxx-commits
mailing list