1$$ This is a pump file for generating file templates. Pump is a python 2$$ script that is part of the Google Test suite of utilities. Description 3$$ can be found here: 4$$ 5$$ http://code.google.com/p/googletest/wiki/PumpManual 6$$ 7 8$var MAX_ARITY = 6 9 10// Copyright (c) 2011 The Chromium Authors. All rights reserved. 11// Use of this source code is governed by a BSD-style license that can be 12// found in the LICENSE file. 13 14#ifndef BASE_BIND_H_ 15#define BASE_BIND_H_ 16#pragma once 17 18#include "base/bind_internal.h" 19#include "base/callback_internal.h" 20 21// See base/callback.h for how to use these functions. 22// 23// IMPLEMENTATION NOTE 24// Though Bind()'s result is meant to be stored in a Callback<> type, it 25// cannot actually return the exact type without requiring a large amount 26// of extra template specializations. The problem is that in order to 27// discern the correct specialization of Callback<>, Bind would need to 28// unwrap the function signature to determine the signature's arity, and 29// whether or not it is a method. 30// 31// Each unique combination of (arity, function_type, num_prebound) where 32// function_type is one of {function, method, const_method} would require 33// one specialization. We eventually have to do a similar number of 34// specializations anyways in the implementation (see the FunctionTraitsN, 35// classes). However, it is avoidable in Bind if we return the result 36// via an indirection like we do below. 37 38namespace base { 39 40$range BOUND 0..MAX_ARITY 41$for BOUND [[ 42$range BOUND_ARG 1..BOUND 43 44$if BOUND == 0 [[ 45 46template <typename Sig> 47internal::InvokerStorageHolder<internal::InvokerStorage0<Sig> > 48Bind(Sig f) { 49 return internal::MakeInvokerStorageHolder( 50 new internal::InvokerStorage0<Sig>(f)); 51} 52 53]] $else [[ 54 55template <typename Sig, $for BOUND_ARG , [[typename P$(BOUND_ARG)]]> 56internal::InvokerStorageHolder<internal::InvokerStorage$(BOUND)<Sig, 57$for BOUND_ARG , [[P$(BOUND_ARG)]]> > 58Bind(Sig f, $for BOUND_ARG , [[const P$(BOUND_ARG)& p$(BOUND_ARG)]]) { 59 return internal::MakeInvokerStorageHolder( 60 new internal::InvokerStorage$(BOUND)<Sig, [[]] 61$for BOUND_ARG , [[P$(BOUND_ARG)]]>( 62 f, $for BOUND_ARG , [[p$(BOUND_ARG)]])); 63} 64 65]] 66 67]] $$ for BOUND 68 69} // namespace base 70 71#endif // BASE_BIND_H_ 72