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
20namespace boost
21{
22template <class T> struct is_nothrow_swappable : boost::integral_constant<bool,
23 boost::is_scalar<T>::value && !boost::is_const<T>::value> {};
24
25template <class T, class U> struct is_nothrow_swappable_with : false_type {};
26template <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
35namespace boost
36{
37
38namespace type_traits_swappable_detail
39{
40
41using std::swap;
42
43template<class T, class U, bool B = noexcept(swap(declval<T>(), declval<U>()))> integral_constant<bool, B> is_nothrow_swappable_with_impl( int );
44template<class T, class U> false_type is_nothrow_swappable_with_impl( ... );
45template<class T, class U>
46struct is_nothrow_swappable_with_helper { typedef decltype( type_traits_swappable_detail::is_nothrow_swappable_with_impl<T, U>(0) ) type; };
47
48template<class T, bool B = noexcept(swap(declval<T&>(), declval<T&>()))> integral_constant<bool, B> is_nothrow_swappable_impl( int );
49template<class T> false_type is_nothrow_swappable_impl( ... );
50template<class T>
51struct 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
55template<class T, class U> struct is_nothrow_swappable_with: type_traits_swappable_detail::is_nothrow_swappable_with_helper<T, U>::type
56{
57};
58
59template<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

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