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/declval.hpp>
13#include <boost/type_traits/integral_constant.hpp>
14#include <boost/type_traits/remove_reference.hpp>
15#include <boost/type_traits/is_function.hpp>
16#include <boost/type_traits/detail/yes_no_type.hpp>
17#include <boost/config/workaround.hpp>
18
19/*
20 * CAUTION:
21 * ~~~~~~~~
22 *
23 * THIS TRAIT EXISTS SOLELY TO GENERATE HARD ERRORS WHEN A ANOTHER TRAIT
24 * WHICH REQUIRES COMPLETE TYPES AS ARGUMENTS IS PASSED AN INCOMPLETE TYPE
25 *
26 * DO NOT MAKE GENERAL USE OF THIS TRAIT, AS THE COMPLETENESS OF A TYPE
27 * VARIES ACROSS TRANSLATION UNITS AS WELL AS WITHIN A SINGLE UNIT.
28 *
29*/
30
31namespace boost {
32
33
34//
35// We will undef this if the trait isn't fully functional:
36//
37#define BOOST_TT_HAS_WORKING_IS_COMPLETE
38
39#if !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_MSVC, <= 1900) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40600)
40
41 namespace detail{
42
43 template <unsigned N>
44 struct ok_tag { double d; char c[N]; };
45
46 template <class T>
47 ok_tag<sizeof(T)> check_is_complete(int);
48 template <class T>
49 char check_is_complete(...);
50 }
51
52 template <class T> struct is_complete
53 : public integral_constant<bool, ::boost::is_function<typename boost::remove_reference<T>::type>::value || (sizeof(boost::detail::check_is_complete<T>(0)) != sizeof(char))> {};
54
55#elif !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) && !BOOST_WORKAROUND(BOOST_GCC_VERSION, < 40500)
56
57 namespace detail
58 {
59
60 template <class T>
61 struct is_complete_imp
62 {
63 template <class U, class = decltype(sizeof(boost::declval< U >())) >
64 static type_traits::yes_type check(U*);
65
66 template <class U>
67 static type_traits::no_type check(...);
68
69 static const bool value = sizeof(check<T>(0)) == sizeof(type_traits::yes_type);
70 };
71
72} // namespace detail
73
74
75 template <class T>
76 struct is_complete : boost::integral_constant<bool, ::boost::is_function<typename boost::remove_reference<T>::type>::value || ::boost::detail::is_complete_imp<T>::value>
77 {};
78 template <class T>
79 struct is_complete<T&> : boost::is_complete<T> {};
80
81#else
82
83 template <class T> struct is_complete
84 : public boost::integral_constant<bool, true> {};
85
86#undef BOOST_TT_HAS_WORKING_IS_COMPLETE
87
88#endif
89
90} // namespace boost
91
92#endif // BOOST_TT_IS_COMPLETE_HPP_INCLUDED
93

source code of include/boost/type_traits/is_complete.hpp