//===----------------------------------------------------------------------===// // // 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 // #include #include #include #include template _Val> constexpr bool test() { std::remove_reference_t item{_Val}; std::optional opt{item}; { assert(*opt == item); assert(&(*opt) == &item); } { assert(*std::as_const(opt) == item); assert(&(*std::as_const(opt)) == &item); } return true; } template constexpr T foo(T val) { return val; } template constexpr bool fn_ref_test() { std::optional opt{foo}; assert(opt.has_value()); assert((*opt)(_Val) == _Val); return true; } template constexpr bool array_ref_test() { T arr[5]{}; std::optional opt{arr}; assert(opt.has_value()); (*opt)[0] = _Val; assert((*opt)[0] == _Val); assert(arr[0] == _Val); return true; } constexpr bool tests() { assert((test())); assert((test())); assert((fn_ref_test())); assert((array_ref_test())); assert((fn_ref_test())); assert((array_ref_test())); return true; } int main(int, char**) { static_assert(tests()); tests(); }