//===----------------------------------------------------------------------===// // // 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 // //===----------------------------------------------------------------------===// // // unique_ptr // test get_deleter() #include #include #include #include "test_macros.h" struct Deleter { TEST_CONSTEXPR_CXX23 Deleter() {} TEST_CONSTEXPR_CXX23 void operator()(void*) const {} TEST_CONSTEXPR_CXX23 int test() { return 5; } TEST_CONSTEXPR_CXX23 int test() const { return 6; } }; template TEST_CONSTEXPR_CXX23 void test_basic() { typedef typename std::conditional::type VT; { std::unique_ptr p; assert(p.get_deleter().test() == 5); } { const std::unique_ptr p; assert(p.get_deleter().test() == 6); } { typedef std::unique_ptr UPtr; const Deleter d; UPtr p(nullptr, d); const UPtr& cp = p; ASSERT_SAME_TYPE(decltype(p.get_deleter()), const Deleter&); ASSERT_SAME_TYPE(decltype(cp.get_deleter()), const Deleter&); assert(p.get_deleter().test() == 6); assert(cp.get_deleter().test() == 6); } { typedef std::unique_ptr UPtr; Deleter d; UPtr p(nullptr, d); const UPtr& cp = p; ASSERT_SAME_TYPE(decltype(p.get_deleter()), Deleter&); ASSERT_SAME_TYPE(decltype(cp.get_deleter()), Deleter&); assert(p.get_deleter().test() == 5); assert(cp.get_deleter().test() == 5); } } TEST_CONSTEXPR_CXX23 bool test() { test_basic(); test_basic(); return true; } int main(int, char**) { test(); #if TEST_STD_VER >= 23 static_assert(test()); #endif return 0; }