Skip to content

Commit c2a28e0

Browse files
yfeldblumfacebook-github-bot
authored andcommitted
some function trait aliases and variables
Reviewed By: Orvid Differential Revision: D74496242 fbshipit-source-id: 88ac4378cfd672acca36a12433ff7cbbcd15f2f0
1 parent e08800f commit c2a28e0

File tree

4 files changed

+69
-17
lines changed

4 files changed

+69
-17
lines changed

folly/ExceptionWrapper-inl.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@ struct exception_wrapper::with_exception_from_fn_ {
2525
};
2626
struct impl_arg_ {
2727
template <typename F>
28-
using apply = typename function_traits<F>::template argument<0>;
28+
using apply = function_arguments_element_t<0, F>;
2929
};
3030
struct impl_bye_;
31-
template <
32-
typename Sig,
33-
typename Traits = function_traits<Sig>,
34-
std::size_t NArgs = Traits::template arguments<type_pack_size_t>::value>
31+
template <typename Sig, std::size_t NArgs = function_arguments_size_v<Sig>>
3532
using impl_ = conditional_t<
36-
Traits::is_variadic,
33+
function_is_variadic_v<Sig>,
3734
impl_var_,
3835
conditional_t<NArgs == 1, impl_arg_, impl_bye_>>;
3936

folly/Traits.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,18 @@ struct member_pointer_traits<M O::*> {
200200
using object_type = O;
201201
};
202202

203+
/// member_pointer_member_t
204+
///
205+
/// The member-type of a pointer-to-member type.
206+
template <typename P>
207+
using member_pointer_member_t = typename member_pointer_traits<P>::member_type;
208+
209+
/// member_pointer_object_t
210+
///
211+
/// The object-type of a pointer-to-member type.
212+
template <typename P>
213+
using member_pointer_object_t = typename member_pointer_traits<P>::object_type;
214+
203215
namespace detail {
204216

205217
struct is_constexpr_default_constructible_ {

folly/channels/detail/MultiplexerTraits.h

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,30 @@ namespace detail {
2525

2626
template <typename MultiplexerType>
2727
struct MultiplexerTraits {
28-
using OnNewSubscriptionPtr = decltype(&MultiplexerType::onNewSubscription);
29-
using OnNewSubscriptionTraits = function_traits<
30-
typename member_pointer_traits<OnNewSubscriptionPtr>::member_type>;
28+
using OnNewSubscriptionSig =
29+
member_pointer_member_t<decltype(&MultiplexerType::onNewSubscription)>;
3130

32-
using OnInputValuePtr = decltype(&MultiplexerType::onInputValue);
33-
using OnInputValueTraits = function_traits<
34-
typename member_pointer_traits<OnInputValuePtr>::member_type>;
31+
using OnInputValueSig =
32+
member_pointer_member_t<decltype(&MultiplexerType::onInputValue)>;
3533

3634
// First parameter type of MultiplexerType::onNewSubscription
37-
using KeyType = typename OnNewSubscriptionTraits::template argument<0>;
35+
using KeyType = function_arguments_element_t<0, OnNewSubscriptionSig>;
3836

3937
// Second parameter type for MultiplexerType::onNewSubscription
4038
using KeyContextType =
41-
std::decay_t<typename OnNewSubscriptionTraits::template argument<1>>;
39+
std::decay_t<function_arguments_element_t<1, OnNewSubscriptionSig>>;
4240

4341
// Third parameter type for MultiplexerType::onNewSubscription
4442
using SubscriptionArgType =
45-
typename OnNewSubscriptionTraits::template argument<2>;
43+
function_arguments_element_t<2, OnNewSubscriptionSig>;
4644

4745
// First parameter value type of MultiplexerType::onInputValue
4846
using InputValueType =
49-
typename OnInputValueTraits::template argument<0>::element_type;
47+
typename function_arguments_element_t<0, OnInputValueSig>::element_type;
5048

5149
// Element type of the returned vector from MultiplexerType::onNewSubscription
5250
using OutputValueType =
53-
typename OnNewSubscriptionTraits::result::StorageType::value_type;
51+
typename function_result_t<OnNewSubscriptionSig>::StorageType::value_type;
5452
};
5553
} // namespace detail
5654
} // namespace channels

folly/functional/traits.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,51 @@ struct function_traits<R(A..., ...) const volatile && noexcept>
449449

450450
// ----
451451

452+
// function_result_t
453+
//
454+
// The result type of the given function type.
455+
template <typename F>
456+
using function_result_t = typename function_traits<F>::result;
457+
458+
// function_arguments_size_t
459+
//
460+
// The size of the arguments list of the given function type, as an
461+
// instantiation of integral_constant.
462+
template <typename F>
463+
using function_arguments_size_t =
464+
typename function_traits<F>::template arguments<type_pack_size_t>;
465+
466+
// function_arguments_size_t
467+
//
468+
// The size of the arguments list of the given function type.
469+
template <typename F>
470+
constexpr std::size_t function_arguments_size_v =
471+
function_arguments_size_t<F>::value;
472+
473+
// function_arguments_element_t
474+
//
475+
// The type of the argument at the given index of the given function type.
476+
template <std::size_t Idx, typename F>
477+
using function_arguments_element_t =
478+
typename function_traits<F>::template argument<Idx>;
479+
480+
// function_is_nothrow_v
481+
//
482+
// True precisely when the given function type is marked noexcept.
483+
template <typename F>
484+
constexpr bool function_is_nothrow_v = function_traits<F>::is_nothrow;
485+
486+
// function_is_variadic_v
487+
//
488+
// True precisely when the given function type is variadic.
489+
//
490+
// Note: C-style variadic, like in printf. Not C++-style variadic-template,
491+
// since concrete function types cannot also be function type templates.
492+
template <typename F>
493+
constexpr bool function_is_variadic_v = function_traits<F>::is_variadic;
494+
495+
// ----
496+
452497
namespace detail {
453498

454499
template <bool Nx, bool Var, typename R>

0 commit comments

Comments
 (0)