From d79df43c5531d2ac691624369932b16e93756057 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Thu, 2 Apr 2015 19:48:01 +0900 Subject: [PATCH] add C++14 version result_of / fix is_destructible --- sprout/functional/ref.hpp | 4 +- sprout/iterator/transform_iterator.hpp | 17 +- sprout/type_traits/is_destructible.hpp | 5 +- sprout/type_traits/result_of.hpp | 199 +++++++++++++++++++++++ sprout/type_traits/std_type_traits.hpp | 5 +- sprout/weed/attr_cnv/results/mem_ptr.hpp | 4 +- 6 files changed, 217 insertions(+), 17 deletions(-) create mode 100644 sprout/type_traits/result_of.hpp diff --git a/sprout/functional/ref.hpp b/sprout/functional/ref.hpp index 13802eba..f667d430 100644 --- a/sprout/functional/ref.hpp +++ b/sprout/functional/ref.hpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include @@ -173,7 +173,7 @@ namespace sprout { } // invocation template - SPROUT_CONSTEXPR typename std::result_of::type + SPROUT_CONSTEXPR typename sprout::result_of::type operator()(Args&&... args) const { return (*t_)(SPROUT_FORWARD(Args, args)...); } diff --git a/sprout/iterator/transform_iterator.hpp b/sprout/iterator/transform_iterator.hpp index dd0c36df..35527e19 100644 --- a/sprout/iterator/transform_iterator.hpp +++ b/sprout/iterator/transform_iterator.hpp @@ -17,6 +17,7 @@ #include #include #include +#include namespace sprout { // @@ -27,7 +28,7 @@ namespace sprout { : public std::iterator< typename sprout::common_iterator_category::type, typename std::remove_reference< - typename std::result_of< + typename sprout::result_of< BinaryFunction ( typename std::iterator_traits::reference, typename std::iterator_traits::reference @@ -36,14 +37,14 @@ namespace sprout { >::type, typename std::iterator_traits::difference_type, typename std::remove_reference< - typename std::result_of< + typename sprout::result_of< BinaryFunction ( typename std::iterator_traits::reference, typename std::iterator_traits::reference ) >::type >::type*, - typename std::result_of< + typename sprout::result_of< BinaryFunction ( typename std::iterator_traits::reference, typename std::iterator_traits::reference @@ -56,7 +57,7 @@ namespace sprout { typedef LIterator iterator_type; typedef RIterator iterator2_type; typedef typename sprout::common_iterator_category::type iterator_category; - typedef typename std::result_of< + typedef typename sprout::result_of< BinaryFunction ( typename std::iterator_traits::reference, typename std::iterator_traits::reference @@ -178,17 +179,17 @@ namespace sprout { : public std::iterator< typename std::iterator_traits::iterator_category, typename std::remove_reference< - typename std::result_of< + typename sprout::result_of< UnaryFunction (typename std::iterator_traits::reference) >::type >::type, typename std::iterator_traits::difference_type, typename std::remove_reference< - typename std::result_of< + typename sprout::result_of< UnaryFunction (typename std::iterator_traits::reference) >::type >::type*, - typename std::result_of< + typename sprout::result_of< UnaryFunction (typename std::iterator_traits::reference) >::type > @@ -197,7 +198,7 @@ namespace sprout { typedef UnaryFunction functor_type; typedef Iterator iterator_type; typedef typename std::iterator_traits::iterator_category iterator_category; - typedef typename std::result_of< + typedef typename sprout::result_of< UnaryFunction (typename std::iterator_traits::reference) >::type reference; typedef typename std::remove_reference::type value_type; diff --git a/sprout/type_traits/is_destructible.hpp b/sprout/type_traits/is_destructible.hpp index 74f154dc..0fc04276 100644 --- a/sprout/type_traits/is_destructible.hpp +++ b/sprout/type_traits/is_destructible.hpp @@ -13,7 +13,6 @@ #include #include #include -#include namespace sprout { // @@ -92,8 +91,8 @@ namespace sprout { template< typename T, - bool = std::is_void::value || (std::is_array::value && !std::extent::value), - bool = std::is_reference::value || std::is_function::value + bool = std::is_void::value || (std::is_array::value && !std::extent::value) || std::is_function::value, + bool = std::is_reference::value || std::is_scalar::value > struct is_destructible_impl; template diff --git a/sprout/type_traits/result_of.hpp b/sprout/type_traits/result_of.hpp new file mode 100644 index 00000000..5f44d460 --- /dev/null +++ b/sprout/type_traits/result_of.hpp @@ -0,0 +1,199 @@ +/*============================================================================= + Copyright (c) 2011-2015 Bolero MURAKAMI + https://github.com/bolero-MURAKAMI/Sprout + + 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) +=============================================================================*/ +#ifndef SPROUT_TYPE_TRAITS_RESULT_OF_HPP +#define SPROUT_TYPE_TRAITS_RESULT_OF_HPP + +#include +#include +#include +#include +#include + +namespace sprout { + // + // result_of + // + namespace detail { + struct result_of_memfun_ref_helper { + public: + template + static sprout::identity().*std::declval())(std::declval()...))> test(int); + template + static sprout::detail::nil_base test(...); + }; +#if defined(_MSC_VER) + template< + typename MemPtr, typename Arg, typename... Args, + typename Base_ = sprout::identity(0))>::type + > + struct result_of_memfun_ref + : public Base_ + {}; +#else + template + struct result_of_memfun_ref + : public sprout::identity(0))>::type + {}; +#endif + + struct result_of_memfun_deref_helper { + public: + template + static sprout::identity()).*std::declval())(std::declval()...))> test(int); + template + static sprout::detail::nil_base test(...); + }; +#if defined(_MSC_VER) + template< + typename MemPtr, typename Arg, typename... Args, + typename Base_ = sprout::identity(0))>::type + > + struct result_of_memfun_deref + : public Base_ + {}; +#else + template + struct result_of_memfun_deref + : public sprout::identity(0))>::type + {}; +#endif + + struct result_of_memobj_ref_helper { + public: + template + static sprout::identity().*std::declval())> test(int); + template + static sprout::detail::nil_base test(...); + }; +#if defined(_MSC_VER) + template< + typename MemPtr, typename Arg, + typename Base_ = sprout::identity(0))>::type + > + struct result_of_memobj_ref + : public Base_ + {}; +#else + template + struct result_of_memobj_ref + : public sprout::identity(0))>::type + {}; +#endif + + struct result_of_memobj_deref_helper { + public: + template + static sprout::identity()).*std::declval())> test(int); + template + static sprout::detail::nil_base test(...); + }; +#if defined(_MSC_VER) + template< + typename MemPtr, typename Arg, + typename Base_ = sprout::identity(0))>::type + > + struct result_of_memobj_deref + : public Base_ + {}; +#else + template + struct result_of_memobj_deref + : public sprout::identity(0))>::type + {}; +#endif + + template + struct result_of_memobj_impl; + template + struct result_of_memobj_impl { + public: + typedef typename std::remove_cv::type>::type argval_type; + typedef R Class::* mem_ptr_type; + typedef typename std::conditional< + std::is_same::value || std::is_base_of::value, + sprout::detail::result_of_memobj_ref, + sprout::detail::result_of_memobj_deref + >::type type; + }; + template + struct result_of_memobj + : public sprout::detail::result_of_memobj_impl::type + {}; + + template + struct result_of_memfun_impl; + template + struct result_of_memfun_impl { + public: + typedef typename std::remove_cv::type>::type argval_type; + typedef R Class::* mem_ptr_type; + typedef typename std::conditional< + std::is_same::value || std::is_base_of::value, + result_of_memfun_ref, + result_of_memfun_deref + >::type type; + }; + template + struct result_of_memfun + : public sprout::detail::result_of_memfun_impl::type + {}; + + struct result_of_other_impl { + public: + template + static sprout::identity()(std::declval()...))> test(int); + template + static sprout::detail::nil_base test(...); + }; +#if defined(_MSC_VER) + template + struct result_of_other_base { + public: + typedef sprout::identity(0))>::type type; + }; + template + struct result_of_other + : public sprout::detail::result_of_other_base::type + {}; +#else + template + struct result_of_other + : public sprout::identity(0))>::type + {}; +#endif + + template + struct result_of_impl + : public sprout::identity::type + {}; + template + struct result_of_impl + : public sprout::detail::result_of_memobj::type, Arg> + {}; + template + struct result_of_impl + : public sprout::detail::result_of_memfun::type, Arg, Args...> + {}; + template + struct result_of_impl + : public sprout::detail::result_of_other + {}; + } //namespace detail + template + struct result_of; + template + struct result_of + : public sprout::detail::result_of_impl< + std::is_member_object_pointer::type>::value, + std::is_member_function_pointer::type>::value, + Functor, Args... + > + {}; +} // namespace sprout + +#endif // #ifndef SPROUT_TYPE_TRAITS_RESULT_OF_HPP diff --git a/sprout/type_traits/std_type_traits.hpp b/sprout/type_traits/std_type_traits.hpp index 91887f03..42964349 100644 --- a/sprout/type_traits/std_type_traits.hpp +++ b/sprout/type_traits/std_type_traits.hpp @@ -14,10 +14,11 @@ #include #include #include -#include #include #include #include +#include +#include #include #if !defined(_LIBCPP_VERSION) || (_LIBCPP_VERSION < 1101) # include @@ -473,7 +474,7 @@ namespace sprout { using std::conditional; // using std::common_type; using std::underlying_type; - using std::result_of; +// using std::result_of; } // namespace sprout #endif // #ifndef SPROUT_TYPE_TRAITS_STD_TYPE_TRAITS_HPP diff --git a/sprout/weed/attr_cnv/results/mem_ptr.hpp b/sprout/weed/attr_cnv/results/mem_ptr.hpp index 7b5dc19c..98f2a9f5 100644 --- a/sprout/weed/attr_cnv/results/mem_ptr.hpp +++ b/sprout/weed/attr_cnv/results/mem_ptr.hpp @@ -8,8 +8,8 @@ #ifndef SPROUT_WEED_ATTR_CNV_RESULTS_MEM_PTR_HPP #define SPROUT_WEED_ATTR_CNV_RESULTS_MEM_PTR_HPP -#include #include +#include namespace sprout { namespace weed { @@ -20,7 +20,7 @@ namespace sprout { // template struct mem_ptr - : public std::result_of + : public sprout::result_of {}; } // namespace results } // namespace attr_cnv