Regenerated, with license and copyright info

[SVN r17419]
This commit is contained in:
Douglas Gregor
2003-02-14 18:05:26 +00:00
parent 07f4c425e3
commit af75e6622e
13 changed files with 203 additions and 93 deletions

View File

@ -1,3 +1,17 @@
# Function library
# Copyright (C) 2001-2003 Douglas Gregor
# Permission to copy, use, sell and distribute this software is granted
# provided this copyright notice appears in all copies. Permission to modify
# the code and to distribute modified code is granted provided this copyright
# notice appears in all copies, and a notice that the code was modified is
# included with the copyright notice. This software is provided "as is"
# without express or implied warranty, and with no claim as to its suitability
# for any purpose.
# For more information, see http://www.boost.org/
# Testing Jamfile autogenerated from XML source # Testing Jamfile autogenerated from XML source
subproject libs/function/test ; subproject libs/function/test ;
@ -15,7 +29,7 @@ DEPENDS all : test ;
test-suite function test-suite function
: :
[ run libs/function/test/function_test.cpp : : : : lib_function_test ] [ run libs/function/test/function_test.cpp ]
[ run libs/function/test/function_n_test.cpp ] [ run libs/function/test/function_n_test.cpp ]

View File

@ -1,3 +1,18 @@
// Boost.Function library
// Copyright (C) 2002-2003 Doug Gregor (gregod@cs.rpi.edu)
//
// Permission to copy, use, sell and distribute this software is granted
// provided this copyright notice appears in all copies.
// Permission to modify the code and to distribute modified code is granted
// provided this copyright notice appears in all copies, and a notice
// that the code was modified is included with the copyright notice.
//
// This software is provided "as is" without express or implied warranty,
// and with no claim as to its suitability for any purpose.
// For more information, see http://www.boost.org
// Make sure we don't try to redefine function2 // Make sure we don't try to redefine function2
#include <boost/function/function2.hpp> #include <boost/function/function2.hpp>

View File

@ -1,41 +1,38 @@
// Function library
// Copyright (C) 2001-2003 Douglas Gregor
// Permission to copy, use, sell and distribute this software is granted
// provided this copyright notice appears in all copies. Permission to modify
// the code and to distribute modified code is granted provided this copyright
// notice appears in all copies, and a notice that the code was modified is
// included with the copyright notice. This software is provided "as is"
// without express or implied warranty, and with no claim as to its
// suitability for any purpose.
// For more information, see http://www.boost.org/
#include <boost/function.hpp> #include <boost/function.hpp>
#include <iostream> #include <iostream>
float mul_ints(int x, int y) { return ((float)x) * y; }
float mul_ints(int x, int y) { return ((float)x) * y; }
struct int_div { struct int_div {
float operator()(int x, int y) const { return ((float)x)/y; }; float operator()(int x, int y) const { return ((float)x)/y; };
}; };
int main() int main()
{ {
boost::function<float (int x, int y)> f;
boost::function<float (int x, int y)> f; f = int_div();
std::cout << f(5, 3) << std::endl;
if (f)
f = int_div();
std::cout << f(5, 3) << std::endl;
if (f)
std::cout << f(5, 3) << std::endl; std::cout << f(5, 3) << std::endl;
else else
std::cout << "f has no target, so it is unsafe to call" << std::endl; std::cout << "f has no target, so it is unsafe to call" << std::endl;
f = 0;
f = 0;
f = &mul_ints; f = &mul_ints;
return 0; return 0;
} }

View File

@ -1,39 +1,36 @@
// Function library
// Copyright (C) 2001-2003 Douglas Gregor
// Permission to copy, use, sell and distribute this software is granted
// provided this copyright notice appears in all copies. Permission to modify
// the code and to distribute modified code is granted provided this copyright
// notice appears in all copies, and a notice that the code was modified is
// included with the copyright notice. This software is provided "as is"
// without express or implied warranty, and with no claim as to its
// suitability for any purpose.
// For more information, see http://www.boost.org/
#include <boost/function.hpp> #include <boost/function.hpp>
#include <iostream> #include <iostream>
float mul_ints(int x, int y) { return ((float)x) * y; }
float mul_ints(int x, int y) { return ((float)x) * y; }
struct int_div { struct int_div {
float operator()(int x, int y) const { return ((float)x)/y; }; float operator()(int x, int y) const { return ((float)x)/y; };
}; };
int main() int main()
{ {
boost::function2<float, int, int> f;
boost::function2<float, int, int> f; f = int_div();
std::cout << f(5, 3) << std::endl;
if (f)
f = int_div();
std::cout << f(5, 3) << std::endl;
if (f)
std::cout << f(5, 3) << std::endl; std::cout << f(5, 3) << std::endl;
else else
std::cout << "f has no target, so it is unsafe to call" << std::endl; std::cout << "f has no target, so it is unsafe to call" << std::endl;
f = 0;
f = 0;
f = &mul_ints; f = &mul_ints;
return 0; return 0;
} }

View File

@ -1,3 +1,16 @@
// Function library
// Copyright (C) 2001-2003 Douglas Gregor
// Permission to copy, use, sell and distribute this software is granted
// provided this copyright notice appears in all copies. Permission to modify
// the code and to distribute modified code is granted provided this copyright
// notice appears in all copies, and a notice that the code was modified is
// included with the copyright notice. This software is provided "as is"
// without express or implied warranty, and with no claim as to its
// suitability for any purpose.
// For more information, see http://www.boost.org/
#include <boost/function.hpp> #include <boost/function.hpp>
@ -8,13 +21,11 @@ struct stateful_type { int operator()(int) const { return 0; } };
int main() int main()
{ {
stateful_type a_function_object; stateful_type a_function_object;
boost::function<int (int)> f; boost::function<int (int)> f;
f = boost::ref(a_function_object); f = boost::ref(a_function_object);
boost::function<int (int)> f2(f); boost::function<int (int)> f2(f);
return 0; return 0;
} }

View File

@ -1,3 +1,16 @@
// Function library
// Copyright (C) 2001-2003 Douglas Gregor
// Permission to copy, use, sell and distribute this software is granted
// provided this copyright notice appears in all copies. Permission to modify
// the code and to distribute modified code is granted provided this copyright
// notice appears in all copies, and a notice that the code was modified is
// included with the copyright notice. This software is provided "as is"
// without express or implied warranty, and with no claim as to its
// suitability for any purpose.
// For more information, see http://www.boost.org/
#include <boost/function.hpp> #include <boost/function.hpp>
@ -8,13 +21,11 @@ struct stateful_type { int operator()(int) const { return 0; } };
int main() int main()
{ {
stateful_type a_function_object; stateful_type a_function_object;
boost::function1<int, int> f; boost::function1<int, int> f;
f = boost::ref(a_function_object); f = boost::ref(a_function_object);
boost::function1<int, int> f2(f); boost::function1<int, int> f2(f);
return 0; return 0;
} }

View File

@ -1,3 +1,18 @@
// Boost.Function library
// Copyright (C) 2002-2003 Doug Gregor (gregod@cs.rpi.edu)
//
// Permission to copy, use, sell and distribute this software is granted
// provided this copyright notice appears in all copies.
// Permission to modify the code and to distribute modified code is granted
// provided this copyright notice appears in all copies, and a notice
// that the code was modified is included with the copyright notice.
//
// This software is provided "as is" without express or implied warranty,
// and with no claim as to its suitability for any purpose.
// For more information, see http://www.boost.org
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>

View File

@ -1,26 +1,35 @@
// Function library
// Copyright (C) 2001-2003 Douglas Gregor
// Permission to copy, use, sell and distribute this software is granted
// provided this copyright notice appears in all copies. Permission to modify
// the code and to distribute modified code is granted provided this copyright
// notice appears in all copies, and a notice that the code was modified is
// included with the copyright notice. This software is provided "as is"
// without express or implied warranty, and with no claim as to its
// suitability for any purpose.
// For more information, see http://www.boost.org/
#include <boost/function.hpp> #include <boost/function.hpp>
#include <iostream> #include <iostream>
#include <functional> #include <functional>
struct X { struct X {
int foo(int); int foo(int);
}; };
int X::foo(int x) { return -x; } int X::foo(int x) { return -x; }
int main() int main()
{ {
boost::function<int (X*, int)> f;
boost::function<int (X*, int)> f;
f = &X::foo; f = &X::foo;
X x; X x;
f(&x, 5); f(&x, 5);
return 0; return 0;
} }

View File

@ -1,26 +1,35 @@
// Function library
// Copyright (C) 2001-2003 Douglas Gregor
// Permission to copy, use, sell and distribute this software is granted
// provided this copyright notice appears in all copies. Permission to modify
// the code and to distribute modified code is granted provided this copyright
// notice appears in all copies, and a notice that the code was modified is
// included with the copyright notice. This software is provided "as is"
// without express or implied warranty, and with no claim as to its
// suitability for any purpose.
// For more information, see http://www.boost.org/
#include <boost/function.hpp> #include <boost/function.hpp>
#include <iostream> #include <iostream>
#include <functional> #include <functional>
struct X { struct X {
int foo(int); int foo(int);
}; };
int X::foo(int x) { return -x; } int X::foo(int x) { return -x; }
int main() int main()
{ {
boost::function2<int, X*, int> f;
boost::function2<int, X*, int> f;
f = &X::foo; f = &X::foo;
X x; X x;
f(&x, 5); f(&x, 5);
return 0; return 0;
} }

View File

@ -1,25 +1,34 @@
// Function library
// Copyright (C) 2001-2003 Douglas Gregor
// Permission to copy, use, sell and distribute this software is granted
// provided this copyright notice appears in all copies. Permission to modify
// the code and to distribute modified code is granted provided this copyright
// notice appears in all copies, and a notice that the code was modified is
// included with the copyright notice. This software is provided "as is"
// without express or implied warranty, and with no claim as to its
// suitability for any purpose.
// For more information, see http://www.boost.org/
#include <boost/function.hpp> #include <boost/function.hpp>
#include <iostream> #include <iostream>
#include <functional> #include <functional>
struct X { struct X {
int foo(int); int foo(int);
}; };
int X::foo(int x) { return -x; } int X::foo(int x) { return -x; }
int main() int main()
{ {
boost::function<int (int)> f; boost::function<int (int)> f;
X x; X x;
f = std::bind1st(std::mem_fun(&X::foo), &x); f = std::bind1st(
std::mem_fun(&X::foo), &x);
f(5); // Call x.foo(5) f(5); // Call x.foo(5)
return 0; return 0;
} }

View File

@ -1,25 +1,34 @@
// Function library
// Copyright (C) 2001-2003 Douglas Gregor
// Permission to copy, use, sell and distribute this software is granted
// provided this copyright notice appears in all copies. Permission to modify
// the code and to distribute modified code is granted provided this copyright
// notice appears in all copies, and a notice that the code was modified is
// included with the copyright notice. This software is provided "as is"
// without express or implied warranty, and with no claim as to its
// suitability for any purpose.
// For more information, see http://www.boost.org/
#include <boost/function.hpp> #include <boost/function.hpp>
#include <iostream> #include <iostream>
#include <functional> #include <functional>
struct X { struct X {
int foo(int); int foo(int);
}; };
int X::foo(int x) { return -x; } int X::foo(int x) { return -x; }
int main() int main()
{ {
boost::function1<int, int> f; boost::function1<int, int> f;
X x; X x;
f = std::bind1st(std::mem_fun(&X::foo), &x); f = std::bind1st(
std::mem_fun(&X::foo), &x);
f(5); // Call x.foo(5) f(5); // Call x.foo(5)
return 0; return 0;
} }

View File

@ -1,9 +1,21 @@
// Function library
// Copyright (C) 2001-2003 Douglas Gregor
// Permission to copy, use, sell and distribute this software is granted
// provided this copyright notice appears in all copies. Permission to modify
// the code and to distribute modified code is granted provided this copyright
// notice appears in all copies, and a notice that the code was modified is
// included with the copyright notice. This software is provided "as is"
// without express or implied warranty, and with no claim as to its
// suitability for any purpose.
// For more information, see http://www.boost.org/
#include <boost/function.hpp> #include <boost/function.hpp>
#include <iostream> #include <iostream>
void do_sum_avg(int values[], int n, int& sum, float& avg) void do_sum_avg(int values[], int n, int& sum, float& avg)
{ {
sum = 0; sum = 0;
@ -11,15 +23,10 @@ void do_sum_avg(int values[], int n, int& sum, float& avg)
sum += values[i]; sum += values[i];
avg = (float)sum / n; avg = (float)sum / n;
} }
int main() int main()
{ {
boost::function<void (int values[], int n, int& sum, float& avg)> sum_avg;
boost::function<void (int values[], int n, int& sum, float& avg)> sum_avg; sum_avg = &do_sum_avg;
sum_avg = &do_sum_avg;
return 0; return 0;
} }

View File

@ -1,9 +1,21 @@
// Function library
// Copyright (C) 2001-2003 Douglas Gregor
// Permission to copy, use, sell and distribute this software is granted
// provided this copyright notice appears in all copies. Permission to modify
// the code and to distribute modified code is granted provided this copyright
// notice appears in all copies, and a notice that the code was modified is
// included with the copyright notice. This software is provided "as is"
// without express or implied warranty, and with no claim as to its
// suitability for any purpose.
// For more information, see http://www.boost.org/
#include <boost/function.hpp> #include <boost/function.hpp>
#include <iostream> #include <iostream>
void do_sum_avg(int values[], int n, int& sum, float& avg) void do_sum_avg(int values[], int n, int& sum, float& avg)
{ {
sum = 0; sum = 0;
@ -11,15 +23,10 @@ void do_sum_avg(int values[], int n, int& sum, float& avg)
sum += values[i]; sum += values[i];
avg = (float)sum / n; avg = (float)sum / n;
} }
int main() int main()
{ {
boost::function4<void, int[], int, int&, float> sum_avg;
boost::function4<void, int[], int, int&, float> sum_avg; sum_avg = &do_sum_avg;
sum_avg = &do_sum_avg;
return 0; return 0;
} }