From b601e8924d9d86e18a02fec5418e9696678fb8a8 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 30 Jun 2020 04:23:39 +0300 Subject: [PATCH] Move result_traits to its own header; add specializations for objects on MSVC >= C++17 --- include/boost/bind/bind.hpp | 24 +-- include/boost/bind/detail/result_traits.hpp | 154 ++++++++++++++++++++ 2 files changed, 155 insertions(+), 23 deletions(-) create mode 100644 include/boost/bind/detail/result_traits.hpp diff --git a/include/boost/bind/bind.hpp b/include/boost/bind/bind.hpp index dfba2e0..a6f3447 100644 --- a/include/boost/bind/bind.hpp +++ b/include/boost/bind/bind.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -59,29 +60,6 @@ template class weak_ptr; namespace _bi // implementation details { -// result_traits - -template struct result_traits -{ - typedef R type; -}; - -#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING) - -struct unspecified {}; - -template struct result_traits -{ - typedef typename F::result_type type; -}; - -template struct result_traits< unspecified, reference_wrapper > -{ - typedef typename F::result_type type; -}; - -#endif - // ref_compare template bool ref_compare( T const & a, T const & b, long ) diff --git a/include/boost/bind/detail/result_traits.hpp b/include/boost/bind/detail/result_traits.hpp new file mode 100644 index 0000000..e6b8a44 --- /dev/null +++ b/include/boost/bind/detail/result_traits.hpp @@ -0,0 +1,154 @@ +#ifndef BOOST_BIND_DETAIL_RESULT_TRAITS_HPP_INCLUDED +#define BOOST_BIND_DETAIL_RESULT_TRAITS_HPP_INCLUDED + +// MS compatible compilers support #pragma once + +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +# pragma once +#endif + +// +// bind/detail/result_traits.hpp +// +// boost/bind.hpp support header, return type deduction +// +// Copyright 2006, 2020 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// +// See http://www.boost.org/libs/bind/bind.html for documentation. +// + +#if defined(_MSVC_LANG) && _MSVC_LANG >= 17 +#include +#endif + +namespace boost +{ + +namespace _bi +{ + +template struct result_traits +{ + typedef R type; +}; + +struct unspecified {}; + +template struct result_traits +{ + typedef typename F::result_type type; +}; + +template struct result_traits< unspecified, reference_wrapper > +{ + typedef typename F::result_type type; +}; + +#if defined(_MSVC_LANG) && _MSVC_LANG >= 17 + +template struct result_traits< unspecified, std::plus > +{ + typedef T type; +}; + +template struct result_traits< unspecified, std::minus > +{ + typedef T type; +}; + +template struct result_traits< unspecified, std::multiplies > +{ + typedef T type; +}; + +template struct result_traits< unspecified, std::divides > +{ + typedef T type; +}; + +template struct result_traits< unspecified, std::modulus > +{ + typedef T type; +}; + +template struct result_traits< unspecified, std::negate > +{ + typedef T type; +}; + +template struct result_traits< unspecified, std::equal_to > +{ + typedef bool type; +}; + +template struct result_traits< unspecified, std::not_equal_to > +{ + typedef bool type; +}; + +template struct result_traits< unspecified, std::greater > +{ + typedef bool type; +}; + +template struct result_traits< unspecified, std::less > +{ + typedef bool type; +}; + +template struct result_traits< unspecified, std::greater_equal > +{ + typedef bool type; +}; + +template struct result_traits< unspecified, std::less_equal > +{ + typedef bool type; +}; + +template struct result_traits< unspecified, std::logical_and > +{ + typedef bool type; +}; + +template struct result_traits< unspecified, std::logical_or > +{ + typedef bool type; +}; + +template struct result_traits< unspecified, std::logical_not > +{ + typedef bool type; +}; + +template struct result_traits< unspecified, std::bit_and > +{ + typedef T type; +}; + +template struct result_traits< unspecified, std::bit_or > +{ + typedef T type; +}; + +template struct result_traits< unspecified, std::bit_xor > +{ + typedef T type; +}; + +template struct result_traits< unspecified, std::bit_not > +{ + typedef T type; +}; + +#endif + +} // namespace _bi + +} // namespace boost + +#endif // #ifndef BOOST_BIND_DETAIL_RESULT_TRAITS_HPP_INCLUDED