1
0
Fork 0
mirror of https://github.com/bolero-MURAKAMI/Sprout synced 2024-11-12 21:09:01 +00:00

add C++14 version result_of / fix is_destructible

This commit is contained in:
bolero-MURAKAMI 2015-04-02 19:48:01 +09:00
parent 1507d435f9
commit d79df43c55
6 changed files with 217 additions and 17 deletions

View file

@ -12,7 +12,7 @@
#include <functional> #include <functional>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/utility/forward.hpp> #include <sprout/utility/forward.hpp>
#include <sprout/type_traits/integral_constant.hpp> #include <sprout/type_traits/std_type_traits.hpp>
#include <sprout/type_traits/identity.hpp> #include <sprout/type_traits/identity.hpp>
#include <sprout/type_traits/has_xxx.hpp> #include <sprout/type_traits/has_xxx.hpp>
#include <sprout/type_traits/inherit_if_xxx.hpp> #include <sprout/type_traits/inherit_if_xxx.hpp>
@ -173,7 +173,7 @@ namespace sprout {
} }
// invocation // invocation
template<typename... Args> template<typename... Args>
SPROUT_CONSTEXPR typename std::result_of<T& (Args&&...)>::type SPROUT_CONSTEXPR typename sprout::result_of<T& (Args&&...)>::type
operator()(Args&&... args) const { operator()(Args&&... args) const {
return (*t_)(SPROUT_FORWARD(Args, args)...); return (*t_)(SPROUT_FORWARD(Args, args)...);
} }

View file

@ -17,6 +17,7 @@
#include <sprout/iterator/distance.hpp> #include <sprout/iterator/distance.hpp>
#include <sprout/iterator/type_traits/common.hpp> #include <sprout/iterator/type_traits/common.hpp>
#include <sprout/utility/swap.hpp> #include <sprout/utility/swap.hpp>
#include <sprout/type_traits/std_type_traits.hpp>
namespace sprout { namespace sprout {
// //
@ -27,7 +28,7 @@ namespace sprout {
: public std::iterator< : public std::iterator<
typename sprout::common_iterator_category<LIterator, RIterator>::type, typename sprout::common_iterator_category<LIterator, RIterator>::type,
typename std::remove_reference< typename std::remove_reference<
typename std::result_of< typename sprout::result_of<
BinaryFunction ( BinaryFunction (
typename std::iterator_traits<LIterator>::reference, typename std::iterator_traits<LIterator>::reference,
typename std::iterator_traits<RIterator>::reference typename std::iterator_traits<RIterator>::reference
@ -36,14 +37,14 @@ namespace sprout {
>::type, >::type,
typename std::iterator_traits<LIterator>::difference_type, typename std::iterator_traits<LIterator>::difference_type,
typename std::remove_reference< typename std::remove_reference<
typename std::result_of< typename sprout::result_of<
BinaryFunction ( BinaryFunction (
typename std::iterator_traits<LIterator>::reference, typename std::iterator_traits<LIterator>::reference,
typename std::iterator_traits<RIterator>::reference typename std::iterator_traits<RIterator>::reference
) )
>::type >::type
>::type*, >::type*,
typename std::result_of< typename sprout::result_of<
BinaryFunction ( BinaryFunction (
typename std::iterator_traits<LIterator>::reference, typename std::iterator_traits<LIterator>::reference,
typename std::iterator_traits<RIterator>::reference typename std::iterator_traits<RIterator>::reference
@ -56,7 +57,7 @@ namespace sprout {
typedef LIterator iterator_type; typedef LIterator iterator_type;
typedef RIterator iterator2_type; typedef RIterator iterator2_type;
typedef typename sprout::common_iterator_category<LIterator, RIterator>::type iterator_category; typedef typename sprout::common_iterator_category<LIterator, RIterator>::type iterator_category;
typedef typename std::result_of< typedef typename sprout::result_of<
BinaryFunction ( BinaryFunction (
typename std::iterator_traits<LIterator>::reference, typename std::iterator_traits<LIterator>::reference,
typename std::iterator_traits<RIterator>::reference typename std::iterator_traits<RIterator>::reference
@ -178,17 +179,17 @@ namespace sprout {
: public std::iterator< : public std::iterator<
typename std::iterator_traits<Iterator>::iterator_category, typename std::iterator_traits<Iterator>::iterator_category,
typename std::remove_reference< typename std::remove_reference<
typename std::result_of< typename sprout::result_of<
UnaryFunction (typename std::iterator_traits<Iterator>::reference) UnaryFunction (typename std::iterator_traits<Iterator>::reference)
>::type >::type
>::type, >::type,
typename std::iterator_traits<Iterator>::difference_type, typename std::iterator_traits<Iterator>::difference_type,
typename std::remove_reference< typename std::remove_reference<
typename std::result_of< typename sprout::result_of<
UnaryFunction (typename std::iterator_traits<Iterator>::reference) UnaryFunction (typename std::iterator_traits<Iterator>::reference)
>::type >::type
>::type*, >::type*,
typename std::result_of< typename sprout::result_of<
UnaryFunction (typename std::iterator_traits<Iterator>::reference) UnaryFunction (typename std::iterator_traits<Iterator>::reference)
>::type >::type
> >
@ -197,7 +198,7 @@ namespace sprout {
typedef UnaryFunction functor_type; typedef UnaryFunction functor_type;
typedef Iterator iterator_type; typedef Iterator iterator_type;
typedef typename std::iterator_traits<iterator_type>::iterator_category iterator_category; typedef typename std::iterator_traits<iterator_type>::iterator_category iterator_category;
typedef typename std::result_of< typedef typename sprout::result_of<
UnaryFunction (typename std::iterator_traits<Iterator>::reference) UnaryFunction (typename std::iterator_traits<Iterator>::reference)
>::type reference; >::type reference;
typedef typename std::remove_reference<reference>::type value_type; typedef typename std::remove_reference<reference>::type value_type;

View file

@ -13,7 +13,6 @@
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/type_traits/integral_constant.hpp> #include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/identity.hpp> #include <sprout/type_traits/identity.hpp>
#include <sprout/type_traits/detail/type_traits_wrapper.hpp>
namespace sprout { namespace sprout {
// //
@ -92,8 +91,8 @@ namespace sprout {
template< template<
typename T, typename T,
bool = std::is_void<T>::value || (std::is_array<T>::value && !std::extent<T>::value), bool = std::is_void<T>::value || (std::is_array<T>::value && !std::extent<T>::value) || std::is_function<T>::value,
bool = std::is_reference<T>::value || std::is_function<T>::value bool = std::is_reference<T>::value || std::is_scalar<T>::value
> >
struct is_destructible_impl; struct is_destructible_impl;
template<typename T> template<typename T>

View file

@ -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 <utility>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/type_traits/identity.hpp>
#include <sprout/detail/nil_base.hpp>
namespace sprout {
//
// result_of
//
namespace detail {
struct result_of_memfun_ref_helper {
public:
template<typename F, typename T, typename... Args>
static sprout::identity<decltype((std::declval<T>().*std::declval<F>())(std::declval<Args>()...))> test(int);
template<typename...>
static sprout::detail::nil_base test(...);
};
#if defined(_MSC_VER)
template<
typename MemPtr, typename Arg, typename... Args,
typename Base_ = sprout::identity<decltype(sprout::detail::result_of_memfun_ref_helper::test<MemPtr, Arg, Args...>(0))>::type
>
struct result_of_memfun_ref
: public Base_
{};
#else
template<typename MemPtr, typename Arg, typename... Args>
struct result_of_memfun_ref
: public sprout::identity<decltype(sprout::detail::result_of_memfun_ref_helper::test<MemPtr, Arg, Args...>(0))>::type
{};
#endif
struct result_of_memfun_deref_helper {
public:
template<typename F, typename T, typename... Args>
static sprout::identity<decltype(((*std::declval<T>()).*std::declval<F>())(std::declval<Args>()...))> test(int);
template<typename...>
static sprout::detail::nil_base test(...);
};
#if defined(_MSC_VER)
template<
typename MemPtr, typename Arg, typename... Args,
typename Base_ = sprout::identity<decltype(sprout::detail::result_of_memfun_deref_helper::test<MemPtr, Arg, Args...>(0))>::type
>
struct result_of_memfun_deref
: public Base_
{};
#else
template<typename MemPtr, typename Arg, typename... Args>
struct result_of_memfun_deref
: public sprout::identity<decltype(sprout::detail::result_of_memfun_deref_helper::test<MemPtr, Arg, Args...>(0))>::type
{};
#endif
struct result_of_memobj_ref_helper {
public:
template<typename F, typename T>
static sprout::identity<decltype(std::declval<T>().*std::declval<F>())> test(int);
template<typename, typename>
static sprout::detail::nil_base test(...);
};
#if defined(_MSC_VER)
template<
typename MemPtr, typename Arg,
typename Base_ = sprout::identity<decltype(sprout::detail::result_of_memobj_ref_helper::test<MemPtr, Arg>(0))>::type
>
struct result_of_memobj_ref
: public Base_
{};
#else
template<typename MemPtr, typename Arg>
struct result_of_memobj_ref
: public sprout::identity<decltype(sprout::detail::result_of_memobj_ref_helper::test<MemPtr, Arg>(0))>::type
{};
#endif
struct result_of_memobj_deref_helper {
public:
template<typename F, typename T>
static sprout::identity<decltype((*std::declval<T>()).*std::declval<F>())> test(int);
template<typename, typename>
static sprout::detail::nil_base test(...);
};
#if defined(_MSC_VER)
template<
typename MemPtr, typename Arg,
typename Base_ = sprout::identity<decltype(sprout::detail::result_of_memobj_deref_helper::test<MemPtr, Arg>(0))>::type
>
struct result_of_memobj_deref
: public Base_
{};
#else
template<typename MemPtr, typename Arg>
struct result_of_memobj_deref
: public sprout::identity<decltype(sprout::detail::result_of_memobj_deref_helper::test<MemPtr, Arg>(0))>::type
{};
#endif
template<typename MemPtr, typename Arg>
struct result_of_memobj_impl;
template<typename R, typename Class, typename Arg>
struct result_of_memobj_impl<R Class::*, Arg> {
public:
typedef typename std::remove_cv<typename std::remove_reference<Arg>::type>::type argval_type;
typedef R Class::* mem_ptr_type;
typedef typename std::conditional<
std::is_same<argval_type, Class>::value || std::is_base_of<Class, argval_type>::value,
sprout::detail::result_of_memobj_ref<mem_ptr_type, Arg>,
sprout::detail::result_of_memobj_deref<mem_ptr_type, Arg>
>::type type;
};
template<typename MemPtr, typename Arg>
struct result_of_memobj
: public sprout::detail::result_of_memobj_impl<MemPtr, Arg>::type
{};
template<typename MemPtr, typename Arg, typename... Args>
struct result_of_memfun_impl;
template<typename R, typename Class, typename Arg, typename... Args>
struct result_of_memfun_impl<R Class::*, Arg, Args...> {
public:
typedef typename std::remove_cv<typename std::remove_reference<Arg>::type>::type argval_type;
typedef R Class::* mem_ptr_type;
typedef typename std::conditional<
std::is_same<argval_type, Class>::value || std::is_base_of<Class, argval_type>::value,
result_of_memfun_ref<mem_ptr_type, Arg, Args...>,
result_of_memfun_deref<mem_ptr_type, Arg, Args...>
>::type type;
};
template<typename MemPtr, typename Arg, typename... Args>
struct result_of_memfun
: public sprout::detail::result_of_memfun_impl<MemPtr, Arg, Args...>::type
{};
struct result_of_other_impl {
public:
template<typename F, typename... Args>
static sprout::identity<decltype(std::declval<F>()(std::declval<Args>()...))> test(int);
template<typename...>
static sprout::detail::nil_base test(...);
};
#if defined(_MSC_VER)
template<typename Functor, typename... Args>
struct result_of_other_base {
public:
typedef sprout::identity<decltype(sprout::detail::result_of_other_impl::test<Functor, Args...>(0))>::type type;
};
template<typename Functor, typename... Args>
struct result_of_other
: public sprout::detail::result_of_other_base<Functor, Args...>::type
{};
#else
template<typename Functor, typename... Args>
struct result_of_other
: public sprout::identity<decltype(sprout::detail::result_of_other_impl::test<Functor, Args...>(0))>::type
{};
#endif
template<bool, bool, typename Functor, typename... Args>
struct result_of_impl
: public sprout::identity<sprout::detail::nil_base>::type
{};
template<typename MemPtr, typename Arg>
struct result_of_impl<true, false, MemPtr, Arg>
: public sprout::detail::result_of_memobj<typename std::decay<MemPtr>::type, Arg>
{};
template<typename MemPtr, typename Arg, typename... Args>
struct result_of_impl<false, true, MemPtr, Arg, Args...>
: public sprout::detail::result_of_memfun<typename std::decay<MemPtr>::type, Arg, Args...>
{};
template<typename Functor, typename... Args>
struct result_of_impl<false, false, Functor, Args...>
: public sprout::detail::result_of_other<Functor, Args...>
{};
} //namespace detail
template<typename Signature>
struct result_of;
template<typename Functor, typename... Args>
struct result_of<Functor(Args...)>
: public sprout::detail::result_of_impl<
std::is_member_object_pointer<typename std::remove_reference<Functor>::type>::value,
std::is_member_function_pointer<typename std::remove_reference<Functor>::type>::value,
Functor, Args...
>
{};
} // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_RESULT_OF_HPP

View file

@ -14,10 +14,11 @@
#include <sprout/detail/predef.hpp> #include <sprout/detail/predef.hpp>
#include <sprout/type_traits/integral_constant.hpp> #include <sprout/type_traits/integral_constant.hpp>
#include <sprout/type_traits/common_type.hpp> #include <sprout/type_traits/common_type.hpp>
#include <sprout/type_traits/is_null_pointer.hpp>
#include <sprout/type_traits/is_signed.hpp> #include <sprout/type_traits/is_signed.hpp>
#include <sprout/type_traits/is_unsigned.hpp> #include <sprout/type_traits/is_unsigned.hpp>
#include <sprout/type_traits/is_destructible.hpp> #include <sprout/type_traits/is_destructible.hpp>
#include <sprout/type_traits/result_of.hpp>
#include <sprout/type_traits/is_null_pointer.hpp>
#include <sprout/type_traits/detail/type_traits_wrapper.hpp> #include <sprout/type_traits/detail/type_traits_wrapper.hpp>
#if !defined(_LIBCPP_VERSION) || (_LIBCPP_VERSION < 1101) #if !defined(_LIBCPP_VERSION) || (_LIBCPP_VERSION < 1101)
# include <sprout/tpp/algorithm/max_element.hpp> # include <sprout/tpp/algorithm/max_element.hpp>
@ -473,7 +474,7 @@ namespace sprout {
using std::conditional; using std::conditional;
// using std::common_type; // using std::common_type;
using std::underlying_type; using std::underlying_type;
using std::result_of; // using std::result_of;
} // namespace sprout } // namespace sprout
#endif // #ifndef SPROUT_TYPE_TRAITS_STD_TYPE_TRAITS_HPP #endif // #ifndef SPROUT_TYPE_TRAITS_STD_TYPE_TRAITS_HPP

View file

@ -8,8 +8,8 @@
#ifndef SPROUT_WEED_ATTR_CNV_RESULTS_MEM_PTR_HPP #ifndef SPROUT_WEED_ATTR_CNV_RESULTS_MEM_PTR_HPP
#define SPROUT_WEED_ATTR_CNV_RESULTS_MEM_PTR_HPP #define SPROUT_WEED_ATTR_CNV_RESULTS_MEM_PTR_HPP
#include <type_traits>
#include <sprout/config.hpp> #include <sprout/config.hpp>
#include <sprout/type_traits/std_type_traits.hpp>
namespace sprout { namespace sprout {
namespace weed { namespace weed {
@ -20,7 +20,7 @@ namespace sprout {
// //
template<typename T, typename U, typename = void> template<typename T, typename U, typename = void>
struct mem_ptr struct mem_ptr
: public std::result_of<U(T)> : public sprout::result_of<U(T)>
{}; {};
} // namespace results } // namespace results
} // namespace attr_cnv } // namespace attr_cnv