• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef WTF_Functional_h
27 #define WTF_Functional_h
28 
29 #include "wtf/Assertions.h"
30 #include "wtf/PassRefPtr.h"
31 #include "wtf/RefPtr.h"
32 #include "wtf/ThreadSafeRefCounted.h"
33 #include "wtf/WeakPtr.h"
34 
35 namespace WTF {
36 
37 // Functional.h provides a very simple way to bind a function pointer and arguments together into a function object
38 // that can be stored, copied and invoked, similar to how boost::bind and std::bind in C++11.
39 
40 // A FunctionWrapper is a class template that can wrap a function pointer or a member function pointer and
41 // provide a unified interface for calling that function.
42 template<typename>
43 class FunctionWrapper;
44 
45 // Bound static functions:
46 
47 template<typename R>
48 class FunctionWrapper<R(*)()> {
49 public:
50     typedef R ResultType;
51 
FunctionWrapper(R (* function)())52     explicit FunctionWrapper(R(*function)())
53         : m_function(function)
54     {
55     }
56 
operator()57     R operator()()
58     {
59         return m_function();
60     }
61 
62 private:
63     R(*m_function)();
64 };
65 
66 template<typename R, typename P1>
67 class FunctionWrapper<R(*)(P1)> {
68 public:
69     typedef R ResultType;
70 
FunctionWrapper(R (* function)(P1))71     explicit FunctionWrapper(R(*function)(P1))
72         : m_function(function)
73     {
74     }
75 
operator()76     R operator()(P1 p1)
77     {
78         return m_function(p1);
79     }
80 
81 private:
82     R(*m_function)(P1);
83 };
84 
85 template<typename R, typename P1, typename P2>
86 class FunctionWrapper<R(*)(P1, P2)> {
87 public:
88     typedef R ResultType;
89 
FunctionWrapper(R (* function)(P1,P2))90     explicit FunctionWrapper(R(*function)(P1, P2))
91         : m_function(function)
92     {
93     }
94 
operator()95     R operator()(P1 p1, P2 p2)
96     {
97         return m_function(p1, p2);
98     }
99 
100 private:
101     R(*m_function)(P1, P2);
102 };
103 
104 template<typename R, typename P1, typename P2, typename P3>
105 class FunctionWrapper<R(*)(P1, P2, P3)> {
106 public:
107     typedef R ResultType;
108 
FunctionWrapper(R (* function)(P1,P2,P3))109     explicit FunctionWrapper(R(*function)(P1, P2, P3))
110         : m_function(function)
111     {
112     }
113 
operator()114     R operator()(P1 p1, P2 p2, P3 p3)
115     {
116         return m_function(p1, p2, p3);
117     }
118 
119 private:
120     R(*m_function)(P1, P2, P3);
121 };
122 
123 template<typename R, typename P1, typename P2, typename P3, typename P4>
124 class FunctionWrapper<R(*)(P1, P2, P3, P4)> {
125 public:
126     typedef R ResultType;
127 
FunctionWrapper(R (* function)(P1,P2,P3,P4))128     explicit FunctionWrapper(R(*function)(P1, P2, P3, P4))
129         : m_function(function)
130     {
131     }
132 
operator()133     R operator()(P1 p1, P2 p2, P3 p3, P4 p4)
134     {
135         return m_function(p1, p2, p3, p4);
136     }
137 
138 private:
139     R(*m_function)(P1, P2, P3, P4);
140 };
141 
142 template<typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
143 class FunctionWrapper<R(*)(P1, P2, P3, P4, P5)> {
144 public:
145     typedef R ResultType;
146 
FunctionWrapper(R (* function)(P1,P2,P3,P4,P5))147     explicit FunctionWrapper(R(*function)(P1, P2, P3, P4, P5))
148         : m_function(function)
149     {
150     }
151 
operator()152     R operator()(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
153     {
154         return m_function(p1, p2, p3, p4, p5);
155     }
156 
157 private:
158     R(*m_function)(P1, P2, P3, P4, P5);
159 };
160 
161 // Bound member functions:
162 
163 template<typename R, typename C>
164 class FunctionWrapper<R(C::*)()> {
165 public:
166     typedef R ResultType;
167 
FunctionWrapper(R (C::* function)())168     explicit FunctionWrapper(R(C::*function)())
169         : m_function(function)
170     {
171     }
172 
operator()173     R operator()(C* c)
174     {
175         return (c->*m_function)();
176     }
177 
operator()178     R operator()(const WeakPtr<C>& c)
179     {
180         C* obj = c.get();
181         if (!obj)
182             return R();
183         return (obj->*m_function)();
184     }
185 
186 private:
187     R(C::*m_function)();
188 };
189 
190 template<typename R, typename C, typename P1>
191 class FunctionWrapper<R(C::*)(P1)> {
192 public:
193     typedef R ResultType;
194 
FunctionWrapper(R (C::* function)(P1))195     explicit FunctionWrapper(R(C::*function)(P1))
196         : m_function(function)
197     {
198     }
199 
operator()200     R operator()(C* c, P1 p1)
201     {
202         return (c->*m_function)(p1);
203     }
204 
operator()205     R operator()(const WeakPtr<C>& c, P1 p1)
206     {
207         C* obj = c.get();
208         if (!obj)
209             return R();
210         return (obj->*m_function)(p1);
211     }
212 
213 private:
214     R(C::*m_function)(P1);
215 };
216 
217 template<typename R, typename C, typename P1, typename P2>
218 class FunctionWrapper<R(C::*)(P1, P2)> {
219 public:
220     typedef R ResultType;
221 
FunctionWrapper(R (C::* function)(P1,P2))222     explicit FunctionWrapper(R(C::*function)(P1, P2))
223         : m_function(function)
224     {
225     }
226 
operator()227     R operator()(C* c, P1 p1, P2 p2)
228     {
229         return (c->*m_function)(p1, p2);
230     }
231 
operator()232     R operator()(const WeakPtr<C>& c, P1 p1, P2 p2)
233     {
234         C* obj = c.get();
235         if (!obj)
236             return R();
237         return (obj->*m_function)(p1, p2);
238     }
239 
240 private:
241     R(C::*m_function)(P1, P2);
242 };
243 
244 template<typename R, typename C, typename P1, typename P2, typename P3>
245 class FunctionWrapper<R(C::*)(P1, P2, P3)> {
246 public:
247     typedef R ResultType;
248 
FunctionWrapper(R (C::* function)(P1,P2,P3))249     explicit FunctionWrapper(R(C::*function)(P1, P2, P3))
250         : m_function(function)
251     {
252     }
253 
operator()254     R operator()(C* c, P1 p1, P2 p2, P3 p3)
255     {
256         return (c->*m_function)(p1, p2, p3);
257     }
258 
operator()259     R operator()(const WeakPtr<C>& c, P1 p1, P2 p2, P3 p3)
260     {
261         C* obj = c.get();
262         if (!obj)
263             return R();
264         return (obj->*m_function)(p1, p2, p3);
265     }
266 
267 private:
268     R(C::*m_function)(P1, P2, P3);
269 };
270 
271 template<typename R, typename C, typename P1, typename P2, typename P3, typename P4>
272 class FunctionWrapper<R(C::*)(P1, P2, P3, P4)> {
273 public:
274     typedef R ResultType;
275 
FunctionWrapper(R (C::* function)(P1,P2,P3,P4))276     explicit FunctionWrapper(R(C::*function)(P1, P2, P3, P4))
277         : m_function(function)
278     {
279     }
280 
operator()281     R operator()(C* c, P1 p1, P2 p2, P3 p3, P4 p4)
282     {
283         return (c->*m_function)(p1, p2, p3, p4);
284     }
285 
operator()286     R operator()(const WeakPtr<C>& c, P1 p1, P2 p2, P3 p3, P4 p4)
287     {
288         C* obj = c.get();
289         if (!obj)
290             return R();
291         return (obj->*m_function)(p1, p2, p3, p4);
292     }
293 
294 private:
295     R(C::*m_function)(P1, P2, P3, P4);
296 };
297 
298 template<typename R, typename C, typename P1, typename P2, typename P3, typename P4, typename P5>
299 class FunctionWrapper<R(C::*)(P1, P2, P3, P4, P5)> {
300 public:
301     typedef R ResultType;
302 
FunctionWrapper(R (C::* function)(P1,P2,P3,P4,P5))303     explicit FunctionWrapper(R(C::*function)(P1, P2, P3, P4, P5))
304         : m_function(function)
305     {
306     }
307 
operator()308     R operator()(C* c, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
309     {
310         return (c->*m_function)(p1, p2, p3, p4, p5);
311     }
312 
operator()313     R operator()(const WeakPtr<C>& c, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
314     {
315         C* obj = c.get();
316         if (!obj)
317             return R();
318         return (obj->*m_function)(p1, p2, p3, p4, p5);
319     }
320 
321 private:
322     R(C::*m_function)(P1, P2, P3, P4, P5);
323 };
324 
325 template<typename T> struct ParamStorageTraits {
326     typedef T StorageType;
327 
wrapParamStorageTraits328     static StorageType wrap(const T& value) { return value; }
unwrapParamStorageTraits329     static const T& unwrap(const StorageType& value) { return value; }
330 };
331 
332 template<typename T> struct ParamStorageTraits<PassRefPtr<T> > {
333     typedef RefPtr<T> StorageType;
334 
335     static StorageType wrap(PassRefPtr<T> value) { return value; }
336     static T* unwrap(const StorageType& value) { return value.get(); }
337 };
338 
339 template<typename T> struct ParamStorageTraits<RefPtr<T> > {
340     typedef RefPtr<T> StorageType;
341 
342     static StorageType wrap(RefPtr<T> value) { return value.release(); }
343     static T* unwrap(const StorageType& value) { return value.get(); }
344 };
345 
346 template<typename> class RetainPtr;
347 
348 template<typename T> struct ParamStorageTraits<RetainPtr<T> > {
349     typedef RetainPtr<T> StorageType;
350 
351     static StorageType wrap(const RetainPtr<T>& value) { return value; }
352     static typename RetainPtr<T>::PtrType unwrap(const StorageType& value) { return value.get(); }
353 };
354 
355 class FunctionImplBase : public ThreadSafeRefCounted<FunctionImplBase> {
356 public:
357     virtual ~FunctionImplBase() { }
358 };
359 
360 template<typename>
361 class FunctionImpl;
362 
363 template<typename R>
364 class FunctionImpl<R()> : public FunctionImplBase {
365 public:
366     virtual R operator()() = 0;
367 };
368 
369 template<typename FunctionWrapper, typename FunctionType>
370 class BoundFunctionImpl;
371 
372 template<typename FunctionWrapper, typename R>
373 class BoundFunctionImpl<FunctionWrapper, R()> FINAL : public FunctionImpl<typename FunctionWrapper::ResultType()> {
374 public:
375     explicit BoundFunctionImpl(FunctionWrapper functionWrapper)
376         : m_functionWrapper(functionWrapper)
377     {
378     }
379 
380     virtual typename FunctionWrapper::ResultType operator()() OVERRIDE
381     {
382         return m_functionWrapper();
383     }
384 
385 private:
386     FunctionWrapper m_functionWrapper;
387 };
388 
389 template<typename FunctionWrapper, typename R, typename P1>
390 class BoundFunctionImpl<FunctionWrapper, R(P1)> FINAL : public FunctionImpl<typename FunctionWrapper::ResultType()> {
391 public:
392     BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1)
393         : m_functionWrapper(functionWrapper)
394         , m_p1(ParamStorageTraits<P1>::wrap(p1))
395     {
396     }
397 
398     virtual typename FunctionWrapper::ResultType operator()() OVERRIDE
399     {
400         return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1));
401     }
402 
403 private:
404     FunctionWrapper m_functionWrapper;
405     typename ParamStorageTraits<P1>::StorageType m_p1;
406 };
407 
408 template<typename FunctionWrapper, typename R, typename P1, typename P2>
409 class BoundFunctionImpl<FunctionWrapper, R(P1, P2)> FINAL : public FunctionImpl<typename FunctionWrapper::ResultType()> {
410 public:
411     BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2)
412         : m_functionWrapper(functionWrapper)
413         , m_p1(ParamStorageTraits<P1>::wrap(p1))
414         , m_p2(ParamStorageTraits<P2>::wrap(p2))
415     {
416     }
417 
418     virtual typename FunctionWrapper::ResultType operator()() OVERRIDE
419     {
420         return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageTraits<P2>::unwrap(m_p2));
421     }
422 
423 private:
424     FunctionWrapper m_functionWrapper;
425     typename ParamStorageTraits<P1>::StorageType m_p1;
426     typename ParamStorageTraits<P2>::StorageType m_p2;
427 };
428 
429 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3>
430 class BoundFunctionImpl<FunctionWrapper, R(P1, P2, P3)> FINAL : public FunctionImpl<typename FunctionWrapper::ResultType()> {
431 public:
432     BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3)
433         : m_functionWrapper(functionWrapper)
434         , m_p1(ParamStorageTraits<P1>::wrap(p1))
435         , m_p2(ParamStorageTraits<P2>::wrap(p2))
436         , m_p3(ParamStorageTraits<P3>::wrap(p3))
437     {
438     }
439 
440     virtual typename FunctionWrapper::ResultType operator()() OVERRIDE
441     {
442         return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageTraits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3));
443     }
444 
445 private:
446     FunctionWrapper m_functionWrapper;
447     typename ParamStorageTraits<P1>::StorageType m_p1;
448     typename ParamStorageTraits<P2>::StorageType m_p2;
449     typename ParamStorageTraits<P3>::StorageType m_p3;
450 };
451 
452 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4>
453 class BoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4)> FINAL : public FunctionImpl<typename FunctionWrapper::ResultType()> {
454 public:
455     BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3, const P4& p4)
456         : m_functionWrapper(functionWrapper)
457         , m_p1(ParamStorageTraits<P1>::wrap(p1))
458         , m_p2(ParamStorageTraits<P2>::wrap(p2))
459         , m_p3(ParamStorageTraits<P3>::wrap(p3))
460         , m_p4(ParamStorageTraits<P4>::wrap(p4))
461     {
462     }
463 
464     virtual typename FunctionWrapper::ResultType operator()() OVERRIDE
465     {
466         return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageTraits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), ParamStorageTraits<P4>::unwrap(m_p4));
467     }
468 
469 private:
470     FunctionWrapper m_functionWrapper;
471     typename ParamStorageTraits<P1>::StorageType m_p1;
472     typename ParamStorageTraits<P2>::StorageType m_p2;
473     typename ParamStorageTraits<P3>::StorageType m_p3;
474     typename ParamStorageTraits<P4>::StorageType m_p4;
475 };
476 
477 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
478 class BoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4, P5)> FINAL : public FunctionImpl<typename FunctionWrapper::ResultType()> {
479 public:
480     BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3, const P4& p4, const P5& p5)
481         : m_functionWrapper(functionWrapper)
482         , m_p1(ParamStorageTraits<P1>::wrap(p1))
483         , m_p2(ParamStorageTraits<P2>::wrap(p2))
484         , m_p3(ParamStorageTraits<P3>::wrap(p3))
485         , m_p4(ParamStorageTraits<P4>::wrap(p4))
486         , m_p5(ParamStorageTraits<P5>::wrap(p5))
487     {
488     }
489 
490     virtual typename FunctionWrapper::ResultType operator()() OVERRIDE
491     {
492         return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageTraits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), ParamStorageTraits<P4>::unwrap(m_p4), ParamStorageTraits<P5>::unwrap(m_p5));
493     }
494 
495 private:
496     FunctionWrapper m_functionWrapper;
497     typename ParamStorageTraits<P1>::StorageType m_p1;
498     typename ParamStorageTraits<P2>::StorageType m_p2;
499     typename ParamStorageTraits<P3>::StorageType m_p3;
500     typename ParamStorageTraits<P4>::StorageType m_p4;
501     typename ParamStorageTraits<P5>::StorageType m_p5;
502 };
503 
504 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
505 class BoundFunctionImpl<FunctionWrapper, R(P1, P2, P3, P4, P5, P6)> FINAL : public FunctionImpl<typename FunctionWrapper::ResultType()> {
506 public:
507     BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3, const P4& p4, const P5& p5, const P6& p6)
508         : m_functionWrapper(functionWrapper)
509         , m_p1(ParamStorageTraits<P1>::wrap(p1))
510         , m_p2(ParamStorageTraits<P2>::wrap(p2))
511         , m_p3(ParamStorageTraits<P3>::wrap(p3))
512         , m_p4(ParamStorageTraits<P4>::wrap(p4))
513         , m_p5(ParamStorageTraits<P5>::wrap(p5))
514         , m_p6(ParamStorageTraits<P6>::wrap(p6))
515     {
516     }
517 
518     virtual typename FunctionWrapper::ResultType operator()() OVERRIDE
519     {
520         return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageTraits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), ParamStorageTraits<P4>::unwrap(m_p4), ParamStorageTraits<P5>::unwrap(m_p5), ParamStorageTraits<P6>::unwrap(m_p6));
521     }
522 
523 private:
524     FunctionWrapper m_functionWrapper;
525     typename ParamStorageTraits<P1>::StorageType m_p1;
526     typename ParamStorageTraits<P2>::StorageType m_p2;
527     typename ParamStorageTraits<P3>::StorageType m_p3;
528     typename ParamStorageTraits<P4>::StorageType m_p4;
529     typename ParamStorageTraits<P5>::StorageType m_p5;
530     typename ParamStorageTraits<P6>::StorageType m_p6;
531 };
532 
533 class FunctionBase {
534 public:
535     bool isNull() const
536     {
537         return !m_impl;
538     }
539 
540 protected:
541     FunctionBase()
542     {
543     }
544 
545     explicit FunctionBase(PassRefPtr<FunctionImplBase> impl)
546         : m_impl(impl)
547     {
548     }
549 
550     template<typename FunctionType> FunctionImpl<FunctionType>* impl() const
551     {
552         return static_cast<FunctionImpl<FunctionType>*>(m_impl.get());
553     }
554 
555 private:
556     RefPtr<FunctionImplBase> m_impl;
557 };
558 
559 template<typename>
560 class Function;
561 
562 template<typename R>
563 class Function<R()> : public FunctionBase {
564 public:
565     Function()
566     {
567     }
568 
569     Function(PassRefPtr<FunctionImpl<R()> > impl)
570         : FunctionBase(impl)
571     {
572     }
573 
574     R operator()() const
575     {
576         ASSERT(!isNull());
577         return impl<R()>()->operator()();
578     }
579 };
580 
581 template<typename FunctionType>
582 Function<typename FunctionWrapper<FunctionType>::ResultType()> bind(FunctionType function)
583 {
584     return Function<typename FunctionWrapper<FunctionType>::ResultType()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType()>(FunctionWrapper<FunctionType>(function))));
585 }
586 
587 template<typename FunctionType, typename A1>
588 Function<typename FunctionWrapper<FunctionType>::ResultType()> bind(FunctionType function, const A1& a1)
589 {
590     return Function<typename FunctionWrapper<FunctionType>::ResultType()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1)>(FunctionWrapper<FunctionType>(function), a1)));
591 }
592 
593 template<typename FunctionType, typename A1, typename A2>
594 Function<typename FunctionWrapper<FunctionType>::ResultType()> bind(FunctionType function, const A1& a1, const A2& a2)
595 {
596     return Function<typename FunctionWrapper<FunctionType>::ResultType()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2)>(FunctionWrapper<FunctionType>(function), a1, a2)));
597 }
598 
599 template<typename FunctionType, typename A1, typename A2, typename A3>
600 Function<typename FunctionWrapper<FunctionType>::ResultType()> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3)
601 {
602     return Function<typename FunctionWrapper<FunctionType>::ResultType()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3)>(FunctionWrapper<FunctionType>(function), a1, a2, a3)));
603 }
604 
605 template<typename FunctionType, typename A1, typename A2, typename A3, typename A4>
606 Function<typename FunctionWrapper<FunctionType>::ResultType()> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3, const A4& a4)
607 {
608     return Function<typename FunctionWrapper<FunctionType>::ResultType()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4)>(FunctionWrapper<FunctionType>(function), a1, a2, a3, a4)));
609 }
610 
611 template<typename FunctionType, typename A1, typename A2, typename A3, typename A4, typename A5>
612 Function<typename FunctionWrapper<FunctionType>::ResultType()> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5)
613 {
614     return Function<typename FunctionWrapper<FunctionType>::ResultType()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4, A5)>(FunctionWrapper<FunctionType>(function), a1, a2, a3, a4, a5)));
615 }
616 
617 template<typename FunctionType, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
618 Function<typename FunctionWrapper<FunctionType>::ResultType()> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6)
619 {
620     return Function<typename FunctionWrapper<FunctionType>::ResultType()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4, A5, A6)>(FunctionWrapper<FunctionType>(function), a1, a2, a3, a4, a5, a6)));
621 }
622 
623 typedef Function<void()> Closure;
624 
625 }
626 
627 using WTF::Function;
628 using WTF::bind;
629 using WTF::Closure;
630 
631 #endif // WTF_Functional_h
632