//===----------------------------------------------------------------------===// // // Copyright 2024 Bloomberg Finance L.P. // // 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 // ADDITIONAL_COMPILE_FLAGS: -freflection // // // [reflection] #include #include #include #include #include #include #include constexpr auto ctx = std::meta::access_context::unchecked(); template constexpr std::meta::info RVal = std::meta::reflect_constant(K); // =============== // class_templates // =============== namespace class_templates { // Handles all template argument kinds. template class C> struct Cls; static_assert(can_substitute(^^Cls, {^^int, RVal<1>, ^^std::array})); [[maybe_unused]] constexpr auto obj1 = substitute(^^Cls, {^^int, RVal<1>, ^^std::array}); static_assert(!is_complete_type(^^Cls)); template class C> struct Cls {}; static_assert(is_complete_type(^^Cls)); // Template arguments are dependent. template class C> consteval auto makeCls() { static_assert(can_substitute(^^Cls, {^^T, RVal, ^^C})); return typename [:substitute(^^Cls, {^^T, RVal, ^^C}):]{}; } [[maybe_unused]] constexpr auto obj2 = makeCls(); // With a dependent type parameter pack. template consteval auto makeTuple(Ts... vs) { static_assert(can_substitute(^^std::tuple, {^^Ts...})); typename [:substitute(^^std::tuple, {^^Ts...}):] tup { vs... }; return tup; } [[maybe_unused]] constexpr auto tup1 = makeTuple(4, true, 'f'); static_assert(get<2>(tup1) == 'f'); // With a dependent non-type parameter pack. template consteval auto returnNumElems() { static_assert(can_substitute(^^std::integer_sequence, {^^int, RVal...})); typename [:substitute(^^std::integer_sequence, {^^int, RVal...}):] seq; return seq.size(); } static_assert(returnNumElems<1, 3, 5>() == 3); // With a dependent template template parameter pack. template