// Copyright (C) 2017 Andrzej Krzemienski. // // Use, modification, and distribution is subject to 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) // // See http://www.boost.org/lib/optional for documentation. // // You are welcome to contact the author at: // akrzemi1@gmail.com #include "boost/optional/optional.hpp" #ifdef __BORLANDC__ #pragma hdrstop #endif #include "boost/core/lightweight_test.hpp" #include "boost/core/lightweight_test_trait.hpp" #include "boost/type_traits/is_base_of.hpp" #include "boost/optional/detail/experimental_traits.hpp" #ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_MOVE_FUNCTIONS struct PrivDefault { private: PrivDefault() {} }; struct CustDefault { CustDefault() {} }; struct CustomizedTrivial { CustomizedTrivial() {} }; struct DeletedDefault { BOOST_DELETED_FUNCTION(DeletedDefault()) }; namespace boost { namespace optional_config { template <> struct optional_uses_direct_storage_for : boost::true_type {}; }} struct CustDtor { ~CustDtor() {} }; struct NoDefault { explicit NoDefault(int) {} }; struct Empty {}; template struct Aggregate { T t; U u; }; struct CustAssign { CustAssign& operator=(CustAssign const&) { return *this; } }; struct CustMove { CustMove(CustMove &&) {} }; void test_type_traits() { // this only tests if type traits are implemented correctly BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for )); BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for )); BOOST_TEST_TRAIT_TRUE(( boost::optional_config::optional_uses_direct_storage_for )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for, double> > )); #ifndef BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable, double> > )); #endif BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for )); BOOST_TEST_TRAIT_FALSE(( boost::optional_config::optional_uses_direct_storage_for > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable > )); } void test_trivial_copyability() { BOOST_TEST_TRAIT_TRUE((boost::is_base_of, boost::optional > )); BOOST_TEST_TRAIT_TRUE((boost::is_base_of, boost::optional > )); BOOST_TEST_TRAIT_TRUE((boost::is_base_of, boost::optional > )); BOOST_TEST_TRAIT_FALSE((boost::is_base_of, boost::optional > )); #ifndef BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable > )); BOOST_TEST_TRAIT_TRUE(( boost::optional_detail::is_type_trivially_copyable > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable > )); #endif BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable > > )); BOOST_TEST_TRAIT_FALSE(( boost::optional_detail::is_type_trivially_copyable, double> > > )); } #endif int main() { #ifndef BOOST_OPTIONAL_DETAIL_NO_DEFAULTED_MOVE_FUNCTIONS test_type_traits(); test_trivial_copyability(); #endif return boost::report_errors(); }