2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef WTF_Functional_h
27 #define WTF_Functional_h
29 #include <wtf/Assertions.h>
30 #include <wtf/PassRefPtr.h>
31 #include <wtf/RefPtr.h>
32 #include <wtf/ThreadSafeRefCounted.h>
34 #if PLATFORM(MAC) && COMPILER_SUPPORTS(BLOCKS)
36 #include <objc/objc-runtime.h>
41 // Functional.h provides a very simple way to bind a function pointer and arguments together into a function object
42 // that can be stored, copied and invoked, similar to how boost::bind and std::bind in C++11.
44 // Helper class template to determine whether a given type has ref and deref member functions
45 // with the right type signature.
47 class HasRefAndDeref {
58 struct Base : public T, public BaseMixin { };
60 template<typename U, U> struct
64 static NoType refCheck(U*, TypeChecker<void (BaseMixin::*)(), &U::ref>* = 0);
65 static YesType refCheck(...);
68 static NoType derefCheck(U*, TypeChecker<void (BaseMixin::*)(), &U::deref>* = 0);
69 static YesType derefCheck(...);
72 static const bool value = sizeof(refCheck(static_cast<Base*>(0))) == sizeof(YesType) && sizeof(derefCheck(static_cast<Base*>(0))) == sizeof(YesType);
75 // A FunctionWrapper is a class template that can wrap a function pointer or a member function pointer and
76 // provide a unified interface for calling that function.
78 class FunctionWrapper;
81 class FunctionWrapper<R (*)()> {
84 static const bool shouldRefFirstParameter = false;
86 explicit FunctionWrapper(R (*function)())
87 : m_function(function)
100 template<typename R, typename P1>
101 class FunctionWrapper<R (*)(P1)> {
103 typedef R ResultType;
104 static const bool shouldRefFirstParameter = false;
106 explicit FunctionWrapper(R (*function)(P1))
107 : m_function(function)
113 return m_function(p1);
120 template<typename R, typename P1, typename P2>
121 class FunctionWrapper<R (*)(P1, P2)> {
123 typedef R ResultType;
124 static const bool shouldRefFirstParameter = false;
126 explicit FunctionWrapper(R (*function)(P1, P2))
127 : m_function(function)
131 R operator()(P1 p1, P2 p2)
133 return m_function(p1, p2);
137 R (*m_function)(P1, P2);
140 template<typename R, typename P1, typename P2, typename P3>
141 class FunctionWrapper<R (*)(P1, P2, P3)> {
143 typedef R ResultType;
144 static const bool shouldRefFirstParameter = false;
146 explicit FunctionWrapper(R (*function)(P1, P2, P3))
147 : m_function(function)
151 R operator()(P1 p1, P2 p2, P3 p3)
153 return m_function(p1, p2, p3);
157 R (*m_function)(P1, P2, P3);
160 template<typename R, typename C>
161 class FunctionWrapper<R (C::*)()> {
163 typedef R ResultType;
164 static const bool shouldRefFirstParameter = HasRefAndDeref<C>::value;
166 explicit FunctionWrapper(R (C::*function)())
167 : m_function(function)
173 return (c->*m_function)();
177 R (C::*m_function)();
180 template<typename R, typename C, typename P1>
181 class FunctionWrapper<R (C::*)(P1)> {
183 typedef R ResultType;
184 static const bool shouldRefFirstParameter = HasRefAndDeref<C>::value;
186 explicit FunctionWrapper(R (C::*function)(P1))
187 : m_function(function)
191 R operator()(C* c, P1 p1)
193 return (c->*m_function)(p1);
197 R (C::*m_function)(P1);
200 template<typename R, typename C, typename P1, typename P2>
201 class FunctionWrapper<R (C::*)(P1, P2)> {
203 typedef R ResultType;
204 static const bool shouldRefFirstParameter = HasRefAndDeref<C>::value;
206 explicit FunctionWrapper(R (C::*function)(P1, P2))
207 : m_function(function)
211 R operator()(C* c, P1 p1, P2 p2)
213 return (c->*m_function)(p1, p2);
217 R (C::*m_function)(P1, P2);
220 template<typename R, typename C, typename P1, typename P2, typename P3>
221 class FunctionWrapper<R (C::*)(P1, P2, P3)> {
223 typedef R ResultType;
224 static const bool shouldRefFirstParameter = HasRefAndDeref<C>::value;
226 explicit FunctionWrapper(R (C::*function)(P1, P2, P3))
227 : m_function(function)
231 R operator()(C* c, P1 p1, P2 p2, P3 p3)
233 return (c->*m_function)(p1, p2, p3);
237 R (C::*m_function)(P1, P2, P3);
240 template<typename R, typename C, typename P1, typename P2, typename P3, typename P4>
241 class FunctionWrapper<R (C::*)(P1, P2, P3, P4)> {
243 typedef R ResultType;
244 static const bool shouldRefFirstParameter = HasRefAndDeref<C>::value;
246 explicit FunctionWrapper(R (C::*function)(P1, P2, P3, P4))
247 : m_function(function)
251 R operator()(C* c, P1 p1, P2 p2, P3 p3, P4 p4)
253 return (c->*m_function)(p1, p2, p3, p4);
257 R (C::*m_function)(P1, P2, P3, P4);
260 template<typename R, typename C, typename P1, typename P2, typename P3, typename P4, typename P5>
261 class FunctionWrapper<R (C::*)(P1, P2, P3, P4, P5)> {
263 typedef R ResultType;
264 static const bool shouldRefFirstParameter = HasRefAndDeref<C>::value;
266 explicit FunctionWrapper(R (C::*function)(P1, P2, P3, P4, P5))
267 : m_function(function)
271 R operator()(C* c, P1 p1, P2 p2, P3 p3, P4 p4, P5 p5)
273 return (c->*m_function)(p1, p2, p3, p4, p5);
277 R (C::*m_function)(P1, P2, P3, P4, P5);
280 #if PLATFORM(MAC) && COMPILER_SUPPORTS(BLOCKS)
282 class FunctionWrapper<R (^)()> {
284 typedef R ResultType;
285 static const bool shouldRefFirstParameter = false;
287 explicit FunctionWrapper(R (^block)())
288 : m_block(Block_copy(block))
292 FunctionWrapper(const FunctionWrapper& other)
293 : m_block(Block_copy(other.m_block))
299 Block_release(m_block);
312 template<typename T, bool shouldRefAndDeref> struct RefAndDeref {
313 static void ref(T) { }
314 static void deref(T) { }
317 template<typename T> struct RefAndDeref<T*, true> {
318 static void ref(T* t) { t->ref(); }
319 static void deref(T* t) { t->deref(); }
322 template<typename T> struct ParamStorageTraits {
323 typedef T StorageType;
325 static StorageType wrap(const T& value) { return value; }
326 static const T& unwrap(const StorageType& value) { return value; }
329 template<typename T> struct ParamStorageTraits<PassRefPtr<T> > {
330 typedef RefPtr<T> StorageType;
332 static StorageType wrap(PassRefPtr<T> value) { return value; }
333 static T* unwrap(const StorageType& value) { return value.get(); }
336 template<typename T> struct ParamStorageTraits<RefPtr<T> > {
337 typedef RefPtr<T> StorageType;
339 static StorageType wrap(RefPtr<T> value) { return value.release(); }
340 static T* unwrap(const StorageType& value) { return value.get(); }
344 template<typename> class RetainPtr;
346 template<typename T> struct ParamStorageTraits<RetainPtr<T> > {
347 typedef RetainPtr<T> StorageType;
349 static StorageType wrap(const RetainPtr<T>& value) { return value; }
350 static typename RetainPtr<T>::PtrType unwrap(const StorageType& value) { return value.get(); }
353 class FunctionImplBase : public ThreadSafeRefCounted<FunctionImplBase> {
355 virtual ~FunctionImplBase() { }
362 class FunctionImpl<R ()> : public FunctionImplBase {
364 virtual R operator()() = 0;
367 template<typename FunctionWrapper, typename FunctionType>
368 class BoundFunctionImpl;
370 template<typename FunctionWrapper, typename R>
371 class BoundFunctionImpl<FunctionWrapper, R ()> : public FunctionImpl<typename FunctionWrapper::ResultType ()> {
373 explicit BoundFunctionImpl(FunctionWrapper functionWrapper)
374 : m_functionWrapper(functionWrapper)
378 virtual R operator()()
380 return m_functionWrapper();
384 FunctionWrapper m_functionWrapper;
387 template<typename FunctionWrapper, typename R, typename P1>
388 class BoundFunctionImpl<FunctionWrapper, R (P1)> : public FunctionImpl<typename FunctionWrapper::ResultType ()> {
391 BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1)
392 : m_functionWrapper(functionWrapper)
393 , m_p1(ParamStorageTraits<P1>::wrap(p1))
395 RefAndDeref<P1, FunctionWrapper::shouldRefFirstParameter>::ref(m_p1);
400 RefAndDeref<P1, FunctionWrapper::shouldRefFirstParameter>::deref(m_p1);
403 virtual R operator()()
405 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1));
409 FunctionWrapper m_functionWrapper;
410 typename ParamStorageTraits<P1>::StorageType m_p1;
413 template<typename FunctionWrapper, typename R, typename P1, typename P2>
414 class BoundFunctionImpl<FunctionWrapper, R (P1, P2)> : public FunctionImpl<typename FunctionWrapper::ResultType ()> {
416 BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2)
417 : m_functionWrapper(functionWrapper)
418 , m_p1(ParamStorageTraits<P1>::wrap(p1))
419 , m_p2(ParamStorageTraits<P2>::wrap(p2))
421 RefAndDeref<P1, FunctionWrapper::shouldRefFirstParameter>::ref(m_p1);
426 RefAndDeref<P1, FunctionWrapper::shouldRefFirstParameter>::deref(m_p1);
429 virtual typename FunctionWrapper::ResultType operator()()
431 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageTraits<P2>::unwrap(m_p2));
435 FunctionWrapper m_functionWrapper;
436 typename ParamStorageTraits<P1>::StorageType m_p1;
437 typename ParamStorageTraits<P2>::StorageType m_p2;
440 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3>
441 class BoundFunctionImpl<FunctionWrapper, R (P1, P2, P3)> : public FunctionImpl<typename FunctionWrapper::ResultType ()> {
443 BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3)
444 : m_functionWrapper(functionWrapper)
445 , m_p1(ParamStorageTraits<P1>::wrap(p1))
446 , m_p2(ParamStorageTraits<P2>::wrap(p2))
447 , m_p3(ParamStorageTraits<P3>::wrap(p3))
449 RefAndDeref<P1, FunctionWrapper::shouldRefFirstParameter>::ref(m_p1);
454 RefAndDeref<P1, FunctionWrapper::shouldRefFirstParameter>::deref(m_p1);
457 virtual typename FunctionWrapper::ResultType operator()()
459 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageTraits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3));
463 FunctionWrapper m_functionWrapper;
464 typename ParamStorageTraits<P1>::StorageType m_p1;
465 typename ParamStorageTraits<P2>::StorageType m_p2;
466 typename ParamStorageTraits<P3>::StorageType m_p3;
469 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4>
470 class BoundFunctionImpl<FunctionWrapper, R (P1, P2, P3, P4)> : public FunctionImpl<typename FunctionWrapper::ResultType ()> {
472 BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3, const P4& p4)
473 : m_functionWrapper(functionWrapper)
474 , m_p1(ParamStorageTraits<P1>::wrap(p1))
475 , m_p2(ParamStorageTraits<P2>::wrap(p2))
476 , m_p3(ParamStorageTraits<P3>::wrap(p3))
477 , m_p4(ParamStorageTraits<P4>::wrap(p4))
479 RefAndDeref<P1, FunctionWrapper::shouldRefFirstParameter>::ref(m_p1);
484 RefAndDeref<P1, FunctionWrapper::shouldRefFirstParameter>::deref(m_p1);
487 virtual typename FunctionWrapper::ResultType operator()()
489 return m_functionWrapper(ParamStorageTraits<P1>::unwrap(m_p1), ParamStorageTraits<P2>::unwrap(m_p2), ParamStorageTraits<P3>::unwrap(m_p3), ParamStorageTraits<P4>::unwrap(m_p4));
493 FunctionWrapper m_functionWrapper;
494 typename ParamStorageTraits<P1>::StorageType m_p1;
495 typename ParamStorageTraits<P2>::StorageType m_p2;
496 typename ParamStorageTraits<P3>::StorageType m_p3;
497 typename ParamStorageTraits<P4>::StorageType m_p4;
500 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
501 class BoundFunctionImpl<FunctionWrapper, R (P1, P2, P3, P4, P5)> : public FunctionImpl<typename FunctionWrapper::ResultType ()> {
503 BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3, const P4& p4, const P5& p5)
504 : m_functionWrapper(functionWrapper)
505 , m_p1(ParamStorageTraits<P1>::wrap(p1))
506 , m_p2(ParamStorageTraits<P2>::wrap(p2))
507 , m_p3(ParamStorageTraits<P3>::wrap(p3))
508 , m_p4(ParamStorageTraits<P4>::wrap(p4))
509 , m_p5(ParamStorageTraits<P5>::wrap(p5))
511 RefAndDeref<P1, FunctionWrapper::shouldRefFirstParameter>::ref(m_p1);
516 RefAndDeref<P1, FunctionWrapper::shouldRefFirstParameter>::deref(m_p1);
519 virtual typename FunctionWrapper::ResultType operator()()
521 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));
525 FunctionWrapper m_functionWrapper;
526 typename ParamStorageTraits<P1>::StorageType m_p1;
527 typename ParamStorageTraits<P2>::StorageType m_p2;
528 typename ParamStorageTraits<P3>::StorageType m_p3;
529 typename ParamStorageTraits<P4>::StorageType m_p4;
530 typename ParamStorageTraits<P5>::StorageType m_p5;
533 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
534 class BoundFunctionImpl<FunctionWrapper, R (P1, P2, P3, P4, P5, P6)> : public FunctionImpl<typename FunctionWrapper::ResultType ()> {
536 BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3, const P4& p4, const P5& p5, const P6& p6)
537 : m_functionWrapper(functionWrapper)
538 , m_p1(ParamStorageTraits<P1>::wrap(p1))
539 , m_p2(ParamStorageTraits<P2>::wrap(p2))
540 , m_p3(ParamStorageTraits<P3>::wrap(p3))
541 , m_p4(ParamStorageTraits<P4>::wrap(p4))
542 , m_p5(ParamStorageTraits<P5>::wrap(p5))
543 , m_p6(ParamStorageTraits<P6>::wrap(p6))
545 RefAndDeref<P1, FunctionWrapper::shouldRefFirstParameter>::ref(m_p1);
550 RefAndDeref<P1, FunctionWrapper::shouldRefFirstParameter>::deref(m_p1);
553 virtual typename FunctionWrapper::ResultType operator()()
555 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));
559 FunctionWrapper m_functionWrapper;
560 typename ParamStorageTraits<P1>::StorageType m_p1;
561 typename ParamStorageTraits<P2>::StorageType m_p2;
562 typename ParamStorageTraits<P3>::StorageType m_p3;
563 typename ParamStorageTraits<P4>::StorageType m_p4;
564 typename ParamStorageTraits<P5>::StorageType m_p5;
565 typename ParamStorageTraits<P6>::StorageType m_p6;
568 template<typename FunctionWrapper, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
569 class BoundFunctionImpl<FunctionWrapper, R (P1, P2, P3, P4, P5, P6, P7)> : public FunctionImpl<typename FunctionWrapper::ResultType ()> {
571 BoundFunctionImpl(FunctionWrapper functionWrapper, const P1& p1, const P2& p2, const P3& p3, const P4& p4, const P5& p5, const P6& p6, const P7& p7)
572 : m_functionWrapper(functionWrapper)
573 , m_p1(ParamStorageTraits<P1>::wrap(p1))
574 , m_p2(ParamStorageTraits<P2>::wrap(p2))
575 , m_p3(ParamStorageTraits<P3>::wrap(p3))
576 , m_p4(ParamStorageTraits<P4>::wrap(p4))
577 , m_p5(ParamStorageTraits<P5>::wrap(p5))
578 , m_p6(ParamStorageTraits<P6>::wrap(p6))
579 , m_p7(ParamStorageTraits<P7>::wrap(p7))
581 RefAndDeref<P1, FunctionWrapper::shouldRefFirstParameter>::ref(m_p1);
586 RefAndDeref<P1, FunctionWrapper::shouldRefFirstParameter>::deref(m_p1);
589 virtual typename FunctionWrapper::ResultType operator()()
591 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), ParamStorageTraits<P7>::unwrap(m_p7));
595 FunctionWrapper m_functionWrapper;
596 typename ParamStorageTraits<P1>::StorageType m_p1;
597 typename ParamStorageTraits<P2>::StorageType m_p2;
598 typename ParamStorageTraits<P3>::StorageType m_p3;
599 typename ParamStorageTraits<P4>::StorageType m_p4;
600 typename ParamStorageTraits<P5>::StorageType m_p5;
601 typename ParamStorageTraits<P6>::StorageType m_p6;
602 typename ParamStorageTraits<P7>::StorageType m_p7;
617 explicit FunctionBase(PassRefPtr<FunctionImplBase> impl)
622 template<typename FunctionType> FunctionImpl<FunctionType>* impl() const
624 return static_cast<FunctionImpl<FunctionType>*>(m_impl.get());
628 RefPtr<FunctionImplBase> m_impl;
635 class Function<R ()> : public FunctionBase {
641 Function(PassRefPtr<FunctionImpl<R ()> > impl)
650 return impl<R ()>()->operator()();
653 #if PLATFORM(MAC) && COMPILER_SUPPORTS(BLOCKS)
654 typedef void (^BlockType)();
655 operator BlockType() const
657 // Declare a RefPtr here so we'll be sure that the underlying FunctionImpl object's
658 // lifecycle is managed correctly.
659 RefPtr<FunctionImpl<R ()> > functionImpl = impl<R ()>();
661 functionImpl->operator()();
664 // This is equivalent to:
666 // return [[block copy] autorelease];
668 // We're using manual objc_msgSend calls here because we don't want to make the entire
669 // file Objective-C. It's useful to be able to implicitly convert a Function to
670 // a block even in C++ code, since that allows us to do things like:
672 // dispatch_async(queue, bind(...));
674 id copiedBlock = objc_msgSend((id)block, sel_registerName("copy"));
675 id autoreleasedBlock = objc_msgSend(copiedBlock, sel_registerName("autorelease"));
676 return (BlockType)autoreleasedBlock;
681 template<typename FunctionType>
682 Function<typename FunctionWrapper<FunctionType>::ResultType ()> bind(FunctionType function)
684 return Function<typename FunctionWrapper<FunctionType>::ResultType ()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType ()>(FunctionWrapper<FunctionType>(function))));
687 template<typename FunctionType, typename A1>
688 Function<typename FunctionWrapper<FunctionType>::ResultType ()> bind(FunctionType function, const A1& a1)
690 return Function<typename FunctionWrapper<FunctionType>::ResultType ()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1)>(FunctionWrapper<FunctionType>(function), a1)));
693 template<typename FunctionType, typename A1, typename A2>
694 Function<typename FunctionWrapper<FunctionType>::ResultType ()> bind(FunctionType function, const A1& a1, const A2& a2)
696 return Function<typename FunctionWrapper<FunctionType>::ResultType ()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2)>(FunctionWrapper<FunctionType>(function), a1, a2)));
699 template<typename FunctionType, typename A1, typename A2, typename A3>
700 Function<typename FunctionWrapper<FunctionType>::ResultType ()> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3)
702 return Function<typename FunctionWrapper<FunctionType>::ResultType ()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3)>(FunctionWrapper<FunctionType>(function), a1, a2, a3)));
705 template<typename FunctionType, typename A1, typename A2, typename A3, typename A4>
706 Function<typename FunctionWrapper<FunctionType>::ResultType ()> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3, const A4& a4)
708 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)));
711 template<typename FunctionType, typename A1, typename A2, typename A3, typename A4, typename A5>
712 Function<typename FunctionWrapper<FunctionType>::ResultType ()> bind(FunctionType function, const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5)
714 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)));
717 template<typename FunctionType, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
718 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)
720 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)));
723 template<typename FunctionType, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
724 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, const A7& a7)
726 return Function<typename FunctionWrapper<FunctionType>::ResultType ()>(adoptRef(new BoundFunctionImpl<FunctionWrapper<FunctionType>, typename FunctionWrapper<FunctionType>::ResultType (A1, A2, A3, A4, A5, A6, A7)>(FunctionWrapper<FunctionType>(function), a1, a2, a3, a4, a5, a6, a7)));
733 #endif // WTF_Functional_h