2 * Copyright 2015 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <boost/type_traits.hpp>
20 namespace folly { namespace fibers {
23 * For any functor F taking >= 1 argument,
24 * FirstArgOf<F>::type is the type of F's first parameter.
26 * Rationale: we want to declare a function func(F), where F has the
27 * signature `void(X)` and func should return T<X> (T and X are some types).
30 * template <typename F>
31 * T<typename FirstArgOf<F>::type>
38 * If F is a pointer-to-member, will contain a typedef type
39 * with the type of F's first parameter
42 struct ExtractFirstMemfn;
44 template <typename Ret, typename T, typename First, typename... Args>
45 struct ExtractFirstMemfn<Ret (T::*)(First, Args...)> {
49 template <typename Ret, typename T, typename First, typename... Args>
50 struct ExtractFirstMemfn<Ret (T::*)(First, Args...) const> {
56 /** Default - use boost */
57 template <typename F, typename Enable = void>
59 typedef typename boost::function_traits<
60 typename std::remove_pointer<F>::type>::arg1_type type;
63 /** Specialization for function objects */
65 struct FirstArgOf<F, typename std::enable_if<std::is_class<F>::value>::type> {
66 typedef typename detail::ExtractFirstMemfn<
67 decltype(&F::operator())>::type type;