2 * Copyright 2017 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>
24 * For any functor F taking >= 1 argument,
25 * FirstArgOf<F>::type is the type of F's first parameter.
27 * Rationale: we want to declare a function func(F), where F has the
28 * signature `void(X)` and func should return T<X> (T and X are some types).
31 * template <typename F>
32 * T<typename FirstArgOf<F>::type>
39 * If F is a pointer-to-member, will contain a typedef type
40 * with the type of F's first parameter
43 struct ExtractFirstMemfn;
45 template <typename Ret, typename T, typename First, typename... Args>
46 struct ExtractFirstMemfn<Ret (T::*)(First, Args...)> {
50 template <typename Ret, typename T, typename First, typename... Args>
51 struct ExtractFirstMemfn<Ret (T::*)(First, Args...) const> {
57 /** Default - use boost */
58 template <typename F, typename Enable = void>
60 typedef typename boost::function_traits<
61 typename std::remove_pointer<F>::type>::arg1_type type;
64 /** Specialization for function objects */
66 struct FirstArgOf<F, typename std::enable_if<std::is_class<F>::value>::type> {
68 typename detail::ExtractFirstMemfn<decltype(&F::operator())>::type type;