Updating trunk VERSION from 833.0 to 834.0
[chromium-blink-merge.git] / base / bind.h.pump
blob62b313f666fcaabd4357e6bb1ef59e2d1053b284
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 $$
8 $var MAX_ARITY = 6
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.
14 #ifndef BASE_BIND_H_
15 #define BASE_BIND_H_
16 #pragma once
18 #include "base/bind_internal.h"
19 #include "base/callback_internal.h"
21 // See base/callback.h for how to use these functions.
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.
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.
38 namespace base {
40 $range BOUND 0..MAX_ARITY
41 $for BOUND [[
42 $range BOUND_ARG 1..BOUND
44 $if BOUND == 0 [[
46 template <typename Sig>
47 internal::InvokerStorageHolder<internal::InvokerStorage0<Sig> >
48 Bind(Sig f) {
49   return internal::MakeInvokerStorageHolder(
50       new internal::InvokerStorage0<Sig>(f));
53 ]] $else [[
55 template <typename Sig, $for BOUND_ARG , [[typename P$(BOUND_ARG)]]>
56 internal::InvokerStorageHolder<internal::InvokerStorage$(BOUND)<Sig,
57 $for BOUND_ARG , [[P$(BOUND_ARG)]]> >
58 Bind(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)]]));
67 ]]  $$ for BOUND
69 }  // namespace base
71 #endif  // BASE_BIND_H_