NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
apply.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_FUNCTIONAL_APPLY_HPP__
2#define NEFORCE_CORE_FUNCTIONAL_APPLY_HPP__
3
10
13NEFORCE_BEGIN_NAMESPACE__
14
16NEFORCE_BEGIN_INNER__
17
18template <template <typename...> class, typename, typename>
19struct __apply_unpack_tuple : false_type {};
20
21template <template <typename...> class Trait, typename T, typename... U>
22struct __apply_unpack_tuple<Trait, T, tuple<U...>> : bool_constant<Trait<T, U...>::value> {};
23
24template <template <typename...> class Trait, typename T, typename... U>
25struct __apply_unpack_tuple<Trait, T, tuple<U...>&> : bool_constant<Trait<T, U&...>::value> {};
26
27template <template <typename...> class Trait, typename T, typename... U>
28struct __apply_unpack_tuple<Trait, T, const tuple<U...>> : bool_constant<Trait<T, const U...>::value> {};
29
30template <template <typename...> class Trait, typename T, typename... U>
31struct __apply_unpack_tuple<Trait, T, const tuple<U...>&> : bool_constant<Trait<T, const U&...>::value> {};
32
33
34template <typename F, typename Tuple, size_t... Idx>
35constexpr auto __apply_impl(F&& f, Tuple&& t, _NEFORCE index_sequence<Idx...>) {
36 return _NEFORCE invoke(_NEFORCE forward<F>(f),
37 _NEFORCE forward<decltype(_NEFORCE get<Idx>(_NEFORCE forward<Tuple>(t)))>(
38 _NEFORCE get<Idx>(_NEFORCE forward<Tuple>(t)))...);
39}
40
41NEFORCE_END_INNER__
43
49
61template <typename Func, typename Tuple>
62constexpr decltype(auto)
63apply(Func&& f, Tuple&& t) noexcept(inner::__apply_unpack_tuple<_NEFORCE is_nothrow_invocable, Func, Tuple>::value) {
65 return inner::__apply_impl(_NEFORCE forward<Func>(f), _NEFORCE forward<Tuple>(t), Indices{});
66}
67 // Tuple
69
70NEFORCE_END_NAMESPACE__
71#endif // NEFORCE_CORE_FUNCTIONAL_APPLY_HPP__
NEFORCE_NODISCARD constexpr T && forward(remove_reference_t< T > &x) noexcept
完美转发左值
NEFORCE_ALWAYS_INLINE enable_if_t< is_void_v< T >, future_result_t< T > > get(future< T > &f)
通用future结果获取函数
integer_sequence< size_t, Values... > index_sequence
索引序列
make_integer_sequence< size_t, Size > make_index_sequence
生成指定长度的索引序列
NEFORCE_CONSTEXPR14 inner::__invoke_result_aux< Callable, Args... >::type invoke(Callable &&f, Args &&... args) noexcept(is_nothrow_invocable< Callable, Args... >::value)
统一调用接口
constexpr decltype(auto) apply(Func &&f, Tuple &&t) noexcept(inner::__apply_unpack_tuple< _NEFORCE is_nothrow_invocable, Func, Tuple >::value)
将元组元素解包作为参数调用函数
bool_constant< false > false_type
表示false的类型
integral_constant< bool, Value > bool_constant
布尔常量包装器
统一调用接口
元组实现