// Copyright (c) 2018-2025 Jean-Louis Leroy // Distributed under the Boost Software License, Version 1.0. // See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef TEST_VIRTUAL_PTR_VALUE_SEMANTICS_HPP #define TEST_VIRTUAL_PTR_VALUE_SEMANTICS_HPP #include #include #include #include #include "test_util.hpp" #include using namespace boost::openmethod; using namespace policies; using namespace detail; struct Animal { virtual ~Animal() { } Animal() = default; Animal(const Animal&) = delete; }; struct Cat : virtual Animal {}; struct Dog : Animal {}; template constexpr bool construct_assign_ok = std::is_constructible_v && std::is_assignable_v; struct NonPolymorphic {}; template void init_test() { BOOST_OPENMETHOD_REGISTER(use_classes); struct id; // without following line, no methods, no v-tables (void)&method)->void, Registry>::fn; initialize(); } struct direct_vector : test_registry_<__COUNTER__> {}; struct indirect_vector : test_registry_<__COUNTER__>::with {}; struct direct_map : test_registry_<__COUNTER__>::with>::without {}; struct indirect_map : direct_map::with {}; using test_policies = boost::mp11::mp_list< direct_vector, indirect_vector, direct_map, indirect_map>; using test_classes = boost::mp11::mp_list; template< template class smart_ptr, template class other_smart_ptr, class Registry> struct check_illegal_smart_ops { // a virtual_ptr cannot be constructed from a smart_ptr to a different class static_assert(!std::is_constructible_v< virtual_ptr, Registry>, smart_ptr>); // a virtual_ptr cannot be constructed from const smart_ptr static_assert( !std::is_constructible_v< virtual_ptr, Registry>, smart_ptr>); // a smart virtual_ptr cannot be constructed from a plain reference or // pointer static_assert(!std::is_constructible_v< virtual_ptr, Registry>, Animal&>); static_assert(!std::is_constructible_v< virtual_ptr, Registry>, Animal*>); static_assert(!std::is_constructible_v< smart_ptr, const other_smart_ptr&>); // smart_ptr p{other_smart_ptr()}; static_assert(!std::is_constructible_v< virtual_ptr, Registry>, virtual_ptr>); // --------------------- // test other properties static_assert(IsSmartPtr, Registry>); static_assert(IsSmartPtr, Registry>); static_assert( std::is_same_v< typename virtual_ptr, Registry>::element_type, Animal>); static_assert( std::is_same_v< decltype(std::declval, Registry>>() .get()), Animal*>); static_assert( std::is_same_v< decltype(*std::declval, Registry>>()), Animal&>); static_assert( std::is_same_v< decltype(std::declval, Registry>>() .pointer()), const smart_ptr&>); static_assert( std::is_same_v< decltype(*std::declval, Registry>>()), Animal&>); }; #endif // TEST_VIRTUAL_PTR_VALUE_SEMANTICS_HPP