1 | |
2 | // (C) Copyright John Maddock 2017. |
3 | // Use, modification and distribution are subject to the Boost Software License, |
4 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
5 | // http://www.boost.org/LICENSE_1_0.txt). |
6 | // |
7 | // See http://www.boost.org/libs/type_traits for most recent version including documentation. |
8 | |
9 | #ifndef BOOST_TT_IS_COMPLETE_HPP_INCLUDED |
10 | #define BOOST_TT_IS_COMPLETE_HPP_INCLUDED |
11 | |
12 | #include <boost/type_traits/integral_constant.hpp> |
13 | #include <boost/type_traits/remove_reference.hpp> |
14 | #include <boost/type_traits/is_function.hpp> |
15 | #include <boost/config/workaround.hpp> |
16 | |
17 | /* |
18 | * CAUTION: |
19 | * ~~~~~~~~ |
20 | * |
21 | * THIS TRAIT EXISTS SOLELY TO GENERATE HARD ERRORS WHEN A ANOTHER TRAIT |
22 | * WHICH REQUIRES COMPLETE TYPES AS ARGUMENTS IS PASSED AN INCOMPLETE TYPE |
23 | * |
24 | * DO NOT MAKE GENERAL USE OF THIS TRAIT, AS THE COMPLETENESS OF A TYPE |
25 | * VARIES ACROSS TRANSLATION UNITS AS WELL AS WITHIN A SINGLE UNIT. |
26 | * |
27 | */ |
28 | |
29 | namespace boost { |
30 | |
31 | |
32 | // |
33 | // We will undef this if the trait isn't fully functional: |
34 | // |
35 | #define BOOST_TT_HAS_WORKING_IS_COMPLETE |
36 | |
37 | #if !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40600) |
38 | |
39 | namespace detail{ |
40 | |
41 | template <unsigned N> |
42 | struct ok_tag { double d; char c[N]; }; |
43 | |
44 | template <class T> |
45 | ok_tag<sizeof(T)> check_is_complete(int); |
46 | template <class T> |
47 | char check_is_complete(...); |
48 | } |
49 | |
50 | template <class T> struct is_complete |
51 | : public integral_constant<bool, ::boost::is_function<typename boost::remove_reference<T>::type>::value || (sizeof(detail::check_is_complete<T>(0)) != sizeof(char))> {}; |
52 | |
53 | #elif !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40500) |
54 | |
55 | namespace detail |
56 | { |
57 | |
58 | template <class T> |
59 | struct is_complete_imp |
60 | { |
61 | template <class U, class = decltype(sizeof(std::declval< U >())) > |
62 | static type_traits::yes_type check(U*); |
63 | |
64 | template <class U> |
65 | static type_traits::no_type check(...); |
66 | |
67 | static const bool value = sizeof(check<T>(0)) == sizeof(type_traits::yes_type); |
68 | }; |
69 | |
70 | } // namespace detail |
71 | |
72 | |
73 | template <class T> |
74 | struct is_complete : boost::integral_constant<bool, ::boost::is_function<typename boost::remove_reference<T>::type>::value || ::boost::detail::is_complete_imp<T>::value> |
75 | {}; |
76 | template <class T> |
77 | struct is_complete<T&> : boost::is_complete<T> {}; |
78 | |
79 | #else |
80 | |
81 | template <class T> struct is_complete |
82 | : public boost::integral_constant<bool, true> {}; |
83 | |
84 | #undef BOOST_TT_HAS_WORKING_IS_COMPLETE |
85 | |
86 | #endif |
87 | |
88 | } // namespace boost |
89 | |
90 | #endif // BOOST_TT_IS_COMPLETE_HPP_INCLUDED |
91 | |