1 | |
2 | // (C) Copyright John Maddock 2015. |
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_ASSIGNABLE_HPP_INCLUDED |
10 | #define BOOST_TT_IS_ASSIGNABLE_HPP_INCLUDED |
11 | |
12 | #include <cstddef> // size_t |
13 | #include <boost/type_traits/integral_constant.hpp> |
14 | #include <boost/detail/workaround.hpp> |
15 | #include <boost/type_traits/is_complete.hpp> |
16 | #include <boost/static_assert.hpp> |
17 | |
18 | namespace boost{ |
19 | |
20 | template <class T, class U = T> struct is_assignable; |
21 | |
22 | } |
23 | |
24 | #if !defined(BOOST_NO_CXX11_DECLTYPE) && !BOOST_WORKAROUND(BOOST_MSVC, < 1800) |
25 | |
26 | #include <boost/type_traits/detail/yes_no_type.hpp> |
27 | #include <boost/type_traits/declval.hpp> |
28 | |
29 | namespace boost{ |
30 | |
31 | namespace detail{ |
32 | |
33 | struct is_assignable_imp |
34 | { |
35 | template<typename T, typename U, typename = decltype(boost::declval<T>() = boost::declval<U>())> |
36 | static boost::type_traits::yes_type test(int); |
37 | |
38 | template<typename, typename> |
39 | static boost::type_traits::no_type test(...); |
40 | }; |
41 | |
42 | } |
43 | |
44 | template <class T, class U> struct is_assignable : public integral_constant<bool, sizeof(detail::is_assignable_imp::test<T, U>(0)) == sizeof(boost::type_traits::yes_type)> |
45 | { |
46 | BOOST_STATIC_ASSERT_MSG(boost::is_complete<T>::value, "Arguments to is_assignable must be complete types" ); |
47 | }; |
48 | template <class T, std::size_t N, class U> struct is_assignable<T[N], U> : public is_assignable<T, U>{}; |
49 | template <class T, std::size_t N, class U> struct is_assignable<T(&)[N], U> : public is_assignable<T&, U>{}; |
50 | template <class T, class U> struct is_assignable<T[], U> : public is_assignable<T, U>{}; |
51 | template <class T, class U> struct is_assignable<T(&)[], U> : public is_assignable<T&, U>{}; |
52 | template <class U> struct is_assignable<void, U> : public integral_constant<bool, false>{}; |
53 | template <class U> struct is_assignable<void const, U> : public integral_constant<bool, false>{}; |
54 | template <class U> struct is_assignable<void volatile, U> : public integral_constant<bool, false>{}; |
55 | template <class U> struct is_assignable<void const volatile, U> : public integral_constant<bool, false>{}; |
56 | |
57 | #else |
58 | |
59 | #include <boost/type_traits/has_trivial_assign.hpp> |
60 | #include <boost/type_traits/remove_reference.hpp> |
61 | |
62 | namespace boost{ |
63 | |
64 | // We don't know how to implement this: |
65 | template <class T, class U> struct is_assignable : public integral_constant<bool, false> |
66 | { |
67 | BOOST_STATIC_ASSERT_MSG(boost::is_complete<T>::value, "Arguments to is_assignable must be complete types" ); |
68 | }; |
69 | template <class T, class U> struct is_assignable<T&, U> : public integral_constant<bool, is_pod<T>::value && is_pod<typename remove_reference<U>::type>::value>{}; |
70 | template <class T, class U> struct is_assignable<const T&, U> : public integral_constant<bool, false>{}; |
71 | template <class U> struct is_assignable<void, U> : public integral_constant<bool, false>{}; |
72 | template <class U> struct is_assignable<void const, U> : public integral_constant<bool, false>{}; |
73 | template <class U> struct is_assignable<void volatile, U> : public integral_constant<bool, false>{}; |
74 | template <class U> struct is_assignable<void const volatile, U> : public integral_constant<bool, false>{}; |
75 | /* |
76 | template <> struct is_assignable<void, void> : public integral_constant<bool, false>{}; |
77 | template <> struct is_assignable<void const, void const> : public integral_constant<bool, false>{}; |
78 | template <> struct is_assignable<void volatile, void volatile> : public integral_constant<bool, false>{}; |
79 | template <> struct is_assignable<void const volatile, void const volatile> : public integral_constant<bool, false>{}; |
80 | */ |
81 | #endif |
82 | |
83 | } // namespace boost |
84 | |
85 | #endif // BOOST_TT_IS_ASSIGNABLE_HPP_INCLUDED |
86 | |