1 // Copyright (C) 2017 Andrzej Krzemienski.
3 // Use, modification, and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/optional for documentation.
9 // You are welcome to contact the author at:
12 #ifndef BOOST_OPTIONAL_DETAIL_EXPERIMENTAL_TRAITS_04NOV2017_HPP
13 #define BOOST_OPTIONAL_DETAIL_EXPERIMENTAL_TRAITS_04NOV2017_HPP
15 #include <boost/config.hpp>
16 #include <boost/detail/workaround.hpp>
17 #include <boost/type_traits.hpp>
19 namespace boost { namespace optional_detail {
21 // The condition to use POD implementation
23 #ifdef BOOST_OPTIONAL_CONFIG_NO_POD_SPEC
24 # define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
25 #elif defined BOOST_OPTIONAL_CONFIG_NO_SPEC_FOR_TRIVIAL_TYPES
26 # define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
27 #elif !defined BOOST_HAS_TRIVIAL_CONSTRUCTOR
28 # define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
29 #elif !defined BOOST_HAS_TRIVIAL_MOVE_ASSIGN
30 # define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
31 #elif !defined BOOST_HAS_TRIVIAL_MOVE_CONSTRUCTOR
32 # define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
33 #elif !defined BOOST_HAS_TRIVIAL_COPY
34 # define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
35 #elif !defined BOOST_HAS_TRIVIAL_ASSIGN
36 # define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
37 #elif !defined BOOST_HAS_TRIVIAL_DESTRUCTOR
38 # define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
39 #elif BOOST_WORKAROUND(BOOST_GCC, < 50000)
40 # define BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
43 #if __cplusplus >= 201103L
44 # if BOOST_WORKAROUND(BOOST_GCC, >= 50000)
45 # define BOOST_OPTIONAL_DETAIL_USE_STD_TYPE_TRAITS
46 # elif (defined BOOST_CLANG)
47 # define BOOST_OPTIONAL_DETAIL_USE_STD_TYPE_TRAITS
52 #ifndef BOOST_OPTIONAL_DETAIL_USE_STD_TYPE_TRAITS
53 # define BOOST_OPTIONAL_DETAIL_HAS_TRIVIAL_CTOR(T) BOOST_HAS_TRIVIAL_CONSTRUCTOR(T)
55 # define BOOST_OPTIONAL_DETAIL_HAS_TRIVIAL_CTOR(T) std::is_trivially_default_constructible<T>::value
60 #ifndef BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
62 struct is_type_trivially_copyable
63 : boost::conditional<(boost::has_trivial_copy_constructor<T>::value &&
64 boost::has_trivial_move_constructor<T>::value &&
65 boost::has_trivial_destructor<T>::value &&
66 boost::has_trivial_move_assign<T>::value &&
67 boost::has_trivial_assign<T>::value),
68 boost::true_type, boost::false_type>::type
72 struct is_type_trivially_copyable
73 : boost::conditional<(boost::is_scalar<T>::value && !boost::is_const<T>::value && !boost::is_volatile<T>::value),
74 boost::true_type, boost::false_type>::type
80 #ifndef BOOST_OPTIONAL_DETAIL_NO_SPEC_FOR_TRIVIAL_TYPES
82 struct optional_uses_direct_storage_for_
83 : boost::conditional< (is_type_trivially_copyable<T>::value && BOOST_OPTIONAL_DETAIL_HAS_TRIVIAL_CTOR(T)) ||
84 (boost::is_scalar<T>::value && !boost::is_const<T>::value && !boost::is_volatile<T>::value)
85 , boost::true_type, boost::false_type>::type
89 struct optional_uses_direct_storage_for_
90 : boost::conditional<(boost::is_scalar<T>::value && !boost::is_const<T>::value && !boost::is_volatile<T>::value)
91 , boost::true_type, boost::false_type>::type
96 }} // boost::optional_detail