[libcxx-commits] [libcxx] [libc++] Implement the `<type_traits>` parts of P1317R2 (PR #151480)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Aug 1 10:26:44 PDT 2025
================
@@ -0,0 +1,598 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++26
+
+// <type_traits>
+
+// template<class Fn, class Tuple> struct is_applicable;
+
+// template<class Fn, class Tuple>
+// constexpr bool is_applicable_v = is_applicable<T, U>::value;
+
+#include <cassert>
+#include <cstddef>
+#include <array>
+#include <complex>
+#include <ranges>
+#include <tuple>
+#include <type_traits>
+#include <utility>
+
+#include "callable_types.h"
+#include "test_iterators.h"
+
+struct empty_aggregate {};
+
+struct derived_from_tuple_int : std::tuple<int> {};
+
+template <>
+struct std::tuple_size<derived_from_tuple_int> : std::integral_constant<std::size_t, 1> {};
+
+template <std::size_t I>
+ requires(I < 1)
+struct std::tuple_element<I, derived_from_tuple_int> {
+ using type = std::tuple_element_t<I, std::tuple<int>>;
+};
+
+template <class Fn, class Tuple, bool Expected>
+void test_is_applicable() {
+ static_assert(std::is_applicable<Fn, Tuple>::value == Expected);
+ static_assert(std::is_applicable_v<Fn, Tuple> == Expected);
+
+ static_assert(std::is_base_of_v<std::bool_constant<Expected>, std::is_applicable<Fn, Tuple>>);
+ static_assert(std::is_convertible_v<std::is_applicable<Fn, Tuple>*, std::bool_constant<Expected>*>);
+}
+
+template <class Func, class Tuple, bool Expected>
+void test_is_applicable_from_function() {
+ static_assert(std::is_function_v<Func>);
+
+ test_is_applicable<Func, Tuple, Expected>();
+ test_is_applicable<Func&, Tuple, Expected>();
+
+ test_is_applicable<Func*, Tuple, Expected>();
+ test_is_applicable<Func*&, Tuple, Expected>();
+ test_is_applicable<Func* const, Tuple, Expected>();
+ test_is_applicable<Func* const&, Tuple, Expected>();
+ test_is_applicable<Func* volatile, Tuple, Expected>();
+ test_is_applicable<Func* volatile&, Tuple, Expected>();
+ test_is_applicable<Func* const volatile, Tuple, Expected>();
+ test_is_applicable<Func* const volatile&, Tuple, Expected>();
+}
+
+void test_valid() {
+ // test array
----------------
ldionne wrote:
It looks like a lot of these tests are generated? Would there be a way to share this between the three test files we're adding in this patch, since there seems to be a lot of redundancy? I'm a bit worried about the maintainability of these tests as written right now (but am quite happy about their apparent exhaustiveness).
https://github.com/llvm/llvm-project/pull/151480
More information about the libcxx-commits
mailing list