mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
add C++14 version result_of / fix is_destructible
This commit is contained in:
parent
1507d435f9
commit
d79df43c55
6 changed files with 217 additions and 17 deletions
|
@ -12,7 +12,7 @@
|
|||
#include <functional>
|
||||
#include <sprout/config.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/has_xxx.hpp>
|
||||
#include <sprout/type_traits/inherit_if_xxx.hpp>
|
||||
|
@ -173,7 +173,7 @@ namespace sprout {
|
|||
}
|
||||
// invocation
|
||||
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 {
|
||||
return (*t_)(SPROUT_FORWARD(Args, args)...);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <sprout/iterator/distance.hpp>
|
||||
#include <sprout/iterator/type_traits/common.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/type_traits/std_type_traits.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -27,7 +28,7 @@ namespace sprout {
|
|||
: public std::iterator<
|
||||
typename sprout::common_iterator_category<LIterator, RIterator>::type,
|
||||
typename std::remove_reference<
|
||||
typename std::result_of<
|
||||
typename sprout::result_of<
|
||||
BinaryFunction (
|
||||
typename std::iterator_traits<LIterator>::reference,
|
||||
typename std::iterator_traits<RIterator>::reference
|
||||
|
@ -36,14 +37,14 @@ namespace sprout {
|
|||
>::type,
|
||||
typename std::iterator_traits<LIterator>::difference_type,
|
||||
typename std::remove_reference<
|
||||
typename std::result_of<
|
||||
typename sprout::result_of<
|
||||
BinaryFunction (
|
||||
typename std::iterator_traits<LIterator>::reference,
|
||||
typename std::iterator_traits<RIterator>::reference
|
||||
)
|
||||
>::type
|
||||
>::type*,
|
||||
typename std::result_of<
|
||||
typename sprout::result_of<
|
||||
BinaryFunction (
|
||||
typename std::iterator_traits<LIterator>::reference,
|
||||
typename std::iterator_traits<RIterator>::reference
|
||||
|
@ -56,7 +57,7 @@ namespace sprout {
|
|||
typedef LIterator iterator_type;
|
||||
typedef RIterator iterator2_type;
|
||||
typedef typename sprout::common_iterator_category<LIterator, RIterator>::type iterator_category;
|
||||
typedef typename std::result_of<
|
||||
typedef typename sprout::result_of<
|
||||
BinaryFunction (
|
||||
typename std::iterator_traits<LIterator>::reference,
|
||||
typename std::iterator_traits<RIterator>::reference
|
||||
|
@ -178,17 +179,17 @@ namespace sprout {
|
|||
: public std::iterator<
|
||||
typename std::iterator_traits<Iterator>::iterator_category,
|
||||
typename std::remove_reference<
|
||||
typename std::result_of<
|
||||
typename sprout::result_of<
|
||||
UnaryFunction (typename std::iterator_traits<Iterator>::reference)
|
||||
>::type
|
||||
>::type,
|
||||
typename std::iterator_traits<Iterator>::difference_type,
|
||||
typename std::remove_reference<
|
||||
typename std::result_of<
|
||||
typename sprout::result_of<
|
||||
UnaryFunction (typename std::iterator_traits<Iterator>::reference)
|
||||
>::type
|
||||
>::type*,
|
||||
typename std::result_of<
|
||||
typename sprout::result_of<
|
||||
UnaryFunction (typename std::iterator_traits<Iterator>::reference)
|
||||
>::type
|
||||
>
|
||||
|
@ -197,7 +198,7 @@ namespace sprout {
|
|||
typedef UnaryFunction functor_type;
|
||||
typedef Iterator iterator_type;
|
||||
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)
|
||||
>::type reference;
|
||||
typedef typename std::remove_reference<reference>::type value_type;
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/identity.hpp>
|
||||
#include <sprout/type_traits/detail/type_traits_wrapper.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -92,8 +91,8 @@ namespace sprout {
|
|||
|
||||
template<
|
||||
typename T,
|
||||
bool = std::is_void<T>::value || (std::is_array<T>::value && !std::extent<T>::value),
|
||||
bool = std::is_reference<T>::value || std::is_function<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_scalar<T>::value
|
||||
>
|
||||
struct is_destructible_impl;
|
||||
template<typename T>
|
||||
|
|
199
sprout/type_traits/result_of.hpp
Normal file
199
sprout/type_traits/result_of.hpp
Normal 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
|
|
@ -14,10 +14,11 @@
|
|||
#include <sprout/detail/predef.hpp>
|
||||
#include <sprout/type_traits/integral_constant.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_unsigned.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>
|
||||
#if !defined(_LIBCPP_VERSION) || (_LIBCPP_VERSION < 1101)
|
||||
# include <sprout/tpp/algorithm/max_element.hpp>
|
||||
|
@ -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
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
#ifndef 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/type_traits/std_type_traits.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace weed {
|
||||
|
@ -20,7 +20,7 @@ namespace sprout {
|
|||
//
|
||||
template<typename T, typename U, typename = void>
|
||||
struct mem_ptr
|
||||
: public std::result_of<U(T)>
|
||||
: public sprout::result_of<U(T)>
|
||||
{};
|
||||
} // namespace results
|
||||
} // namespace attr_cnv
|
||||
|
|
Loading…
Reference in a new issue