1 #ifndef BOOST_TYPE_TRAITS_IS_NOTHROW_SWAPPABLE_HPP_INCLUDED
2 #define BOOST_TYPE_TRAITS_IS_NOTHROW_SWAPPABLE_HPP_INCLUDED
3 
4 //  Copyright 2017 Peter Dimov
5 //
6 //  Distributed under the Boost Software License, Version 1.0.
7 //  See accompanying file LICENSE_1_0.txt or copy at
8 //  http://www.boost.org/LICENSE_1_0.txt
9 
10 #include <boost/config.hpp>
11 #include <boost/config/workaround.hpp>
12 
13 #if defined(BOOST_NO_SFINAE_EXPR) || defined(BOOST_NO_CXX11_NOEXCEPT) || defined(BOOST_NO_CXX11_DECLTYPE) \
14    || defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) || BOOST_WORKAROUND(BOOST_GCC, < 40700)
15 
16 #include <boost/type_traits/is_scalar.hpp>
17 #include <boost/type_traits/is_const.hpp>
18 #include <boost/type_traits/integral_constant.hpp>
19 
20 namespace boost
21 {
22 template <class T> struct is_nothrow_swappable : boost::integral_constant<bool,
23     boost::is_scalar<T>::value && !boost::is_const<T>::value> {};
24 
25 template <class T, class U> struct is_nothrow_swappable_with : false_type {};
26 template <class T> struct is_nothrow_swappable_with<T, T> : is_nothrow_swappable<T> {};
27 }
28 
29 #else
30 
31 #include <boost/type_traits/declval.hpp>
32 #include <boost/type_traits/integral_constant.hpp>
33 #include <algorithm>
34 
35 namespace boost
36 {
37 
38 namespace type_traits_swappable_detail
39 {
40 
41 using std::swap;
42 
43 template<class T, class U, bool B = noexcept(swap(declval<T>(), declval<U>()))> integral_constant<bool, B> is_nothrow_swappable_with_impl( int );
44 template<class T, class U> false_type is_nothrow_swappable_with_impl( ... );
45 template<class T, class U>
46 struct is_nothrow_swappable_with_helper { typedef decltype( type_traits_swappable_detail::is_nothrow_swappable_with_impl<T, U>(0) ) type; };
47 
48 template<class T, bool B = noexcept(swap(declval<T&>(), declval<T&>()))> integral_constant<bool, B> is_nothrow_swappable_impl( int );
49 template<class T> false_type is_nothrow_swappable_impl( ... );
50 template<class T>
51 struct is_nothrow_swappable_helper { typedef decltype( type_traits_swappable_detail::is_nothrow_swappable_impl<T>(0) ) type; };
52 
53 } // namespace type_traits_swappable_detail
54 
55 template<class T, class U> struct is_nothrow_swappable_with: type_traits_swappable_detail::is_nothrow_swappable_with_helper<T, U>::type
56 {
57 };
58 
59 template<class T> struct is_nothrow_swappable: type_traits_swappable_detail::is_nothrow_swappable_helper<T>::type
60 {
61 };
62 
63 } // namespace boost
64 
65 #endif
66 
67 #endif // #ifndef BOOST_TYPE_TRAITS_IS_NOTHROW_SWAPPABLE_HPP_INCLUDED
68