Commit 1b2c1c83 authored by Steve O'Brien's avatar Steve O'Brien Committed by Facebook Github Bot

folly/fibers/Traits: remove dependency on boost/type_traits

Summary: Small change so that a template class `ExtractFirstArg` can do the same thing without relying on an expensive header, `boost/type_traits.hpp`.

Reviewed By: yfeldblum

Differential Revision: D7781675

fbshipit-source-id: 1e5f431217da6cdd31ba1d77a8fc2b19a43808aa
parent 641b9df1
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
*/ */
#pragma once #pragma once
#include <boost/type_traits.hpp> #include <type_traits>
namespace folly { namespace folly {
namespace fibers { namespace fibers {
...@@ -35,37 +35,41 @@ namespace fibers { ...@@ -35,37 +35,41 @@ namespace fibers {
namespace detail { namespace detail {
/** template <typename F>
* If F is a pointer-to-member, will contain a typedef type struct ExtractFirstArg;
* with the type of F's first parameter
*/
template <typename>
struct ExtractFirstMemfn;
template <typename Ret, typename T, typename First, typename... Args> template <typename Ret, typename T, typename First, typename... Args>
struct ExtractFirstMemfn<Ret (T::*)(First, Args...)> { struct ExtractFirstArg<Ret (T::*)(First, Args...)> {
typedef First type; typedef First type;
}; };
template <typename Ret, typename T, typename First, typename... Args> template <typename Ret, typename T, typename First, typename... Args>
struct ExtractFirstMemfn<Ret (T::*)(First, Args...) const> { struct ExtractFirstArg<Ret (T::*)(First, Args...) const> {
typedef First type;
};
template <typename Ret, typename First, typename... Args>
struct ExtractFirstArg<Ret(First, Args...)> {
typedef First type; typedef First type;
}; };
} // namespace detail } // namespace detail
/** Default - use boost */
template <typename F, typename Enable = void> template <typename F, typename Enable = void>
struct FirstArgOf { struct FirstArgOf;
typedef typename boost::function_traits<
typename std::remove_pointer<F>::type>::arg1_type type; /** Specialization for non-function-object callables */
template <typename F>
struct FirstArgOf<F, typename std::enable_if<!std::is_class<F>::value>::type> {
typedef typename detail::ExtractFirstArg<
typename std::remove_pointer<F>::type>::type type;
}; };
/** Specialization for function objects */ /** Specialization for function objects */
template <typename F> template <typename F>
struct FirstArgOf<F, typename std::enable_if<std::is_class<F>::value>::type> { struct FirstArgOf<F, typename std::enable_if<std::is_class<F>::value>::type> {
typedef typedef typename FirstArgOf<decltype(&F::operator())>::type type;
typename detail::ExtractFirstMemfn<decltype(&F::operator())>::type type;
}; };
} // namespace fibers } // namespace fibers
} // namespace folly } // namespace folly
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment