Attention: you have posted C++ template code on PHP mailing list. Please
pay a $100 fine immediately and carefully proceed to the exit.

-Andrei

On Mon, 07 Feb 2005, Terje Slettebų wrote:
> To illustrate its use, I can give a "simple" example in C++:
> 
> #include <iostream>
> 
> class plus
> {
> public:
>   int operator()(int a,int b) { return a+b; }
> };
> 
> template<class T>
> class apply1
> {
> public:
>   apply1(int v) : bound_1st(v) {}
> 
>   int operator()(int b) { return T()(bound_1st, b); }
> 
> private:
>   int bound_1st;
> };
> 
> int main()
> {
>   std::cout << plus()(1,3) << "\n";
> 
>   std::cout << apply1<plus>(1)(3) << "\n";
> }
> 
> The first line of main() creates a "plus" object ("plus()"), and calls its
> overloaded operator() with 1 and 3, giving 4. The second line creates an
> "apply1" object (taking "plus" as a type parameter, and 1 as a constructor
> parameter - "apply1<plus>(1)"), and then its overloaded operator() is called
> with 3. As the first parameter, 1, is "bound" by "apply1", the result is,
> once again, 4. So the above prints "4 4" (separated by newline).
> 
> apply1<plus>(1) creates a function object which has bound one of plus'es
> parameters, which means it becomes a "1 + ?" function, effectively, or in
> other words, a partial application of the "plus" function (object).
> 
> Naturally, you may get a similar effect in PHP by using named member
> functions rather than operator(). As another poster pointed out, $object()
> already has a (different) meaning.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to