diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/functional | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/functional')
34 files changed, 2758 insertions, 0 deletions
diff --git a/src/boost/libs/functional/binders.html b/src/boost/libs/functional/binders.html new file mode 100644 index 00000000..c3443fee --- /dev/null +++ b/src/boost/libs/functional/binders.html @@ -0,0 +1,161 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> + +<html> +<head> + <meta http-equiv="Content-Language" content="en-us"> + <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> + + <title>Boost Function Object Adapter Library</title> +</head> + +<body bgcolor="#FFFFFF" text="#000000"> + <table border="1" bgcolor="#007F7F" cellpadding="2" summary=""> + <tr> + <td bgcolor="#FFFFFF"><img src="../../boost.png" alt= + "boost.png (6897 bytes)" width="277" height="86"></td> + + <td><a href="../../index.htm"><font face="Arial" color= + "#FFFFFF"><big>Home</big></font></a></td> + + <td><a href="../libraries.htm"><font face="Arial" color= + "#FFFFFF"><big>Libraries</big></font></a></td> + + <td><a href="http://www.boost.org/people/people.htm"><font face="Arial" color= + "#FFFFFF"><big>People</big></font></a></td> + + <td><a href="http://www.boost.org/more/faq.htm"><font face="Arial" color= + "#FFFFFF"><big>FAQ</big></font></a></td> + + <td><a href="../../more/index.htm"><font face="Arial" color= + "#FFFFFF"><big>More</big></font></a></td> + </tr> + </table> + + <h1>Binders</h1> + + <p>The header <a href="../../boost/functional.hpp">functional.hpp</a> + provides enhanced versions of both the binder function object adapters from + the C++ Standard Library (§20.3.6):</p> + + <ul> + <li><tt>binder1st</tt></li> + + <li><tt>binder2nd</tt></li> + </ul> + + <p>As well as the corresponding helper functions</p> + + <ul> + <li><tt>bind1st</tt></li> + + <li><tt>bind2nd</tt></li> + </ul> + + <p>The key benefit of these adapters over those in the Standard Library is + they avoid the problem of <a href="#refref">references to + references.</a></p> + + <h3>Usage</h3> + + <p>Usage is identical to the standard binders. For example,</p> + + <blockquote> + <pre> +class Foo { +public: + void bar(std::ostream &); + // ... +}; +// ... +std::vector<Foo> c; +// ... +std::for_each(c.begin(), c.end(), + boost::bind2nd(boost::mem_fun_ref(&Foo::bar), std::cout)); +</pre> + </blockquote> + + <h3 id="refref">References to References</h3> + + <p>Consider the usage example above</p> + + <blockquote> + <pre> +class Foo { +public: + void bar(<strong>std::ostream &</strong>); + // ... +}; +// ... +std::for_each(c.begin(), c.end(), + boost::bind2nd(boost::mem_fun_ref(&Foo::bar), std::cout)); +</pre> + </blockquote> + + <p>If this had been written using <tt>std::bind2nd</tt> and + <tt>std::mem_fun_ref</tt>, it would be unlikely to compile.</p> + + <p>The problem arises because <tt>bar</tt> takes a reference argument. The + Standard defines <tt>std::mem_fun_ref</tt> such that it creates a function + object whose <tt>second_argument_type</tt> will be + <tt>std::ostream&</tt>.</p> + + <p>The call to <tt>bind2nd</tt> creates a <tt>binder2nd</tt> which the + Standard defines as follows:</p> + + <blockquote> + <pre> +template <class Operation> +class binder2nd + : public unary_function<typename Operation::first_argument_type, + typename Operation::result_type> { +... +public: + binder2nd(const Operation& x, + <strong>const typename Operation::second_argument_type& y</strong>); + ... +</pre> + </blockquote> + + <p>Since our operation's <tt>second_argument_type</tt> is + <tt>std::ostream&</tt>, the type of <tt>y</tt> in the constructor would + be <tt>std::ostream&&</tt>. Since you cannot have a reference to a + reference, at this point we should get a compilation error because + references to references are illegal in C++ (but see <a href= + "http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#106">C++ + Standard core language active issues list</a>).</p> + + <p>The binders in this library avoid this problem by using the Boost + <tt><a href="../utility/call_traits.htm">call_traits</a></tt> + templates.</p> + + <p>Our constructor is declared</p> + + <blockquote> + <pre> +binder2nd(const Operation& x, + <strong>typename call_traits< + typename binary_traits<Operation>::second_argument_type + >::param_type y</strong>) +</pre> + </blockquote> + + <p>As a result, <tt>y</tt> has a type of <tt>std::ostream&</tt>, and + our example compiles.</p> + <hr> + + <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src= + "../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional" + height="31" width="88"></a></p> + + <p>Revised + <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->02 + December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38510" --></p> + + <p><i>Copyright © 2000 Cadenza New Zealand Ltd.</i></p> + + <p><i>Distributed under the Boost Software License, Version 1.0. (See + accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or + copy at <a href= + "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p> +</body> +</html> diff --git a/src/boost/libs/functional/factory/index.html b/src/boost/libs/functional/factory/index.html new file mode 100644 index 00000000..18030298 --- /dev/null +++ b/src/boost/libs/functional/factory/index.html @@ -0,0 +1,15 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> + <head> + <meta http-equiv="refresh" content="0; URL=doc/html/index.html"> + </head> + <body> + Automatic redirection failed, click this + <a href="doc/html/index.html">link</a> <hr> + <p>© Copyright Tobias Schwinger, 2009</p> + <p>Distributed under the Boost Software License, Version 1.0. (See + accompanying file <a href="../../../LICENSE_1_0.txt"> + LICENSE_1_0.txt</a> or copy at + <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p> + </body> +</html> diff --git a/src/boost/libs/functional/factory/test/Jamfile b/src/boost/libs/functional/factory/test/Jamfile new file mode 100644 index 00000000..7030e939 --- /dev/null +++ b/src/boost/libs/functional/factory/test/Jamfile @@ -0,0 +1,20 @@ +# Copyright 2007,2008 Tobias Schwinger +# +# Copyright 2019 Glen Joseph Fernandes +# (glenjofe@gmail.com) +# +# Distributed under the Boost Software License, Version 1.0. +# (http://www.boost.org/LICENSE_1_0.txt) + +import testing ; + +run value_factory.cpp ; +run value_factory_args.cpp ; +run value_factory_move.cpp ; +run factory.cpp ; +run factory_args.cpp ; +run factory_move.cpp ; +run factory_with_allocator.cpp ; +run factory_with_std_allocator.cpp ; +run factory_allocator_throws.cpp ; +run factory_default_allocator.cpp : : : <exception-handling>off ; diff --git a/src/boost/libs/functional/factory/test/factory.cpp b/src/boost/libs/functional/factory/test/factory.cpp new file mode 100644 index 00000000..2da5cf41 --- /dev/null +++ b/src/boost/libs/functional/factory/test/factory.cpp @@ -0,0 +1,87 @@ +/* +Copyright 2007 Tobias Schwinger + +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/functional/factory.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/scoped_ptr.hpp> + +class sum { +public: + explicit sum(int i0 = 0, int i1 = 0, int i2 = 0, int i3 = 0, + int i4 = 0, int i5 = 0, int i6 = 0, int i7 = 0, + int i8 = 0, int i9 = 0) + : value_(i0 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9) { } + + int get() const { + return value_; + } + +private: + int value_; +}; + +int main() +{ + boost::factory<sum*> x; + int a = 1; + int b = 2; + int c = 3; + int d = 4; + int e = 5; + int f = 6; + int g = 7; + int h = 8; + int i = 9; + int j = 10; + { + boost::scoped_ptr<sum> s(x()); + BOOST_TEST(s->get() == 0); + } + { + boost::scoped_ptr<sum> s(x(a)); + BOOST_TEST(s->get() == 1); + } + { + boost::scoped_ptr<sum> s(x(a, b)); + BOOST_TEST(s->get() == 3); + } + { + boost::scoped_ptr<sum> s(x(a, b, c)); + BOOST_TEST(s->get() == 6); + } + { + boost::scoped_ptr<sum> s(x(a, b, c, d)); + BOOST_TEST(s->get() == 10); + } + { + boost::scoped_ptr<sum> s(x(a, b, c, d, e)); + BOOST_TEST(s->get() == 15); + } + { + boost::scoped_ptr<sum> s(x(a, b, c, d, e, f)); + BOOST_TEST(s->get() == 21); + } + { + boost::scoped_ptr<sum> s(x(a, b, c, d, e, f, g)); + BOOST_TEST(s->get() == 28); + } + { + boost::scoped_ptr<sum> s(x(a, b, c, d, e, f, g, h)); + BOOST_TEST(s->get() == 36); + } + { + boost::scoped_ptr<sum> s(x(a, b, c, d, e, f, g, h, i)); + BOOST_TEST(s->get() == 45); + } + { + boost::scoped_ptr<sum> s(x(a, b, c, d, e, f, g, h, i, j)); + BOOST_TEST(s->get() == 55); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/functional/factory/test/factory_allocator_throws.cpp b/src/boost/libs/functional/factory/test/factory_allocator_throws.cpp new file mode 100644 index 00000000..0186b793 --- /dev/null +++ b/src/boost/libs/functional/factory/test/factory_allocator_throws.cpp @@ -0,0 +1,85 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/functional/factory.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/shared_ptr.hpp> + +struct type { + explicit type(bool b) { + if (b) { + throw true; + } + } +}; + +template<class T> +class creator { +public: + static int count; + + typedef T value_type; + typedef T* pointer; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + ++count; + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + --count; + ::operator delete(ptr); + } +}; + +template<class T> +int creator<T>::count = 0; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +int main() +{ + bool b = true; + try { + boost::shared_ptr<type> s(boost::factory<boost::shared_ptr<type>, + creator<void>, + boost::factory_alloc_for_pointee_and_deleter>()(b)); + } catch (...) { + BOOST_TEST(creator<type>::count == 0); + } + try { + boost::shared_ptr<type> s(boost::factory<boost::shared_ptr<type>, + creator<void>, + boost::factory_passes_alloc_to_smart_pointer>()(b)); + } catch (...) { + BOOST_TEST(creator<type>::count == 0); + } + return boost::report_errors(); +} + diff --git a/src/boost/libs/functional/factory/test/factory_args.cpp b/src/boost/libs/functional/factory/test/factory_args.cpp new file mode 100644 index 00000000..bec677e8 --- /dev/null +++ b/src/boost/libs/functional/factory/test/factory_args.cpp @@ -0,0 +1,42 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/functional/factory.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/scoped_ptr.hpp> + +class sum { +public: + explicit sum(int a = 0, int b = 0, int c = 0, int d = 0, + int e = 0, int f = 0, int g = 0, int h = 0, + int i = 0, int j = 0, int k = 0, int l = 0) + : value_(a + b + c + d + e + f + g + h + i + j + k + l) { } + + int get() const { + return value_; + } + +private: + int value_; +}; + +int main() +{ + boost::scoped_ptr<sum> s(boost::factory<sum*>()(1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12)); + BOOST_TEST(s->get() == 78); + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/functional/factory/test/factory_default_allocator.cpp b/src/boost/libs/functional/factory/test/factory_default_allocator.cpp new file mode 100644 index 00000000..c6450ba4 --- /dev/null +++ b/src/boost/libs/functional/factory/test/factory_default_allocator.cpp @@ -0,0 +1,56 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/functional/factory.hpp> +#include <boost/core/default_allocator.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/shared_ptr.hpp> +#include <boost/config.hpp> +#include <exception> + +#if defined(BOOST_NO_EXCEPTIONS) +namespace boost { + +BOOST_NORETURN void throw_exception(const std::exception&) +{ + std::terminate(); +} + +} +#endif + +class sum { +public: + sum(int a, int b) + : value_(a + b) { } + + int get() const { + return value_; + } + +private: + int value_; +}; + +int main() +{ + int a = 1; + int b = 2; + { + boost::shared_ptr<sum> s(boost::factory<boost::shared_ptr<sum>, + boost::default_allocator<void>, + boost::factory_alloc_for_pointee_and_deleter>()(a, b)); + BOOST_TEST(s->get() == 3); + } + { + boost::shared_ptr<sum> s(boost::factory<boost::shared_ptr<sum>, + boost::default_allocator<void>, + boost::factory_passes_alloc_to_smart_pointer>()(a, b)); + BOOST_TEST(s->get() == 3); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/functional/factory/test/factory_move.cpp b/src/boost/libs/functional/factory/test/factory_move.cpp new file mode 100644 index 00000000..5b6575b9 --- /dev/null +++ b/src/boost/libs/functional/factory/test/factory_move.cpp @@ -0,0 +1,55 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/functional/factory.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/scoped_ptr.hpp> + +class arg { +public: + explicit arg(int n) + : value_(n) { } + + arg(arg&& a) + : value_(a.value_) { } + + int get() const { + return value_; + } + +private: + int value_; +}; + +class sum { +public: + explicit sum(arg&& a1, arg&& a2) + : value_(a1.get() + a2.get()) { } + + int get() const { + return value_; + } + +private: + int value_; +}; + +int main() +{ + boost::scoped_ptr<sum> s(boost::factory<sum*>()(arg(1), arg(2))); + BOOST_TEST(s->get() == 3); + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/functional/factory/test/factory_with_allocator.cpp b/src/boost/libs/functional/factory/test/factory_with_allocator.cpp new file mode 100644 index 00000000..f321df18 --- /dev/null +++ b/src/boost/libs/functional/factory/test/factory_with_allocator.cpp @@ -0,0 +1,95 @@ +/* +Copyright 2007 Tobias Schwinger + +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/functional/factory.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/shared_ptr.hpp> + +class sum { +public: + sum(int a, int b) + : value_(a + b) { } + + int get() const { + return value_; + } + +private: + int value_; +}; + +template<class T> +class creator { +public: + static int count; + + typedef T value_type; + typedef T* pointer; + + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + ++count; + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + --count; + ::operator delete(ptr); + } +}; + +template<class T> +int creator<T>::count = 0; + +template<class T, class U> +inline bool +operator==(const creator<T>&, const creator<U>&) +{ + return true; +} + +template<class T, class U> +inline bool +operator!=(const creator<T>&, const creator<U>&) +{ + return false; +} + +int main() +{ + int a = 1; + int b = 2; + { + boost::shared_ptr<sum> s(boost::factory<boost::shared_ptr<sum>, + creator<void>, + boost::factory_alloc_for_pointee_and_deleter>()(a, b)); + BOOST_TEST(creator<sum>::count == 1); + BOOST_TEST(s->get() == 3); + } + BOOST_TEST(creator<sum>::count == 0); + { + boost::shared_ptr<sum> s(boost::factory<boost::shared_ptr<sum>, + creator<void>, + boost::factory_passes_alloc_to_smart_pointer>()(a, b)); + BOOST_TEST(creator<sum>::count == 1); + BOOST_TEST(s->get() == 3); + } + BOOST_TEST(creator<sum>::count == 0); + return boost::report_errors(); +} + diff --git a/src/boost/libs/functional/factory/test/factory_with_std_allocator.cpp b/src/boost/libs/functional/factory/test/factory_with_std_allocator.cpp new file mode 100644 index 00000000..6b7def46 --- /dev/null +++ b/src/boost/libs/functional/factory/test/factory_with_std_allocator.cpp @@ -0,0 +1,46 @@ +/* +Copyright 2007 Tobias Schwinger +Copyright 2017 Daniel James + +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/functional/factory.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/smart_ptr/shared_ptr.hpp> +#include <memory> + +class sum { +public: + sum(int a, int b) + : value_(a + b) { } + + int get() const { + return value_; + } + +private: + int value_; +}; + +int main() +{ + int a = 1; + int b = 2; + { + boost::shared_ptr<sum> s(boost::factory<boost::shared_ptr<sum>, + std::allocator<char>, + boost::factory_alloc_for_pointee_and_deleter>()(a, b)); + BOOST_TEST(s->get() == 3); + } + { + boost::shared_ptr<sum> s(boost::factory<boost::shared_ptr<sum>, + std::allocator<char>, + boost::factory_passes_alloc_to_smart_pointer>()(a, b)); + BOOST_TEST(s->get() == 3); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/functional/factory/test/value_factory.cpp b/src/boost/libs/functional/factory/test/value_factory.cpp new file mode 100644 index 00000000..7af232c0 --- /dev/null +++ b/src/boost/libs/functional/factory/test/value_factory.cpp @@ -0,0 +1,86 @@ +/* +Copyright 2007 Tobias Schwinger + +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/functional/value_factory.hpp> +#include <boost/core/lightweight_test.hpp> + +class sum { +public: + explicit sum(int i0 = 0, int i1 = 0, int i2 = 0, int i3 = 0, + int i4 = 0, int i5 = 0, int i6 = 0, int i7 = 0, + int i8 = 0, int i9 = 0) + : value_(i0 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9) { } + + int get() const { + return value_; + } + +private: + int value_; +}; + +int main() +{ + boost::value_factory<sum> x; + int a = 1; + int b = 2; + int c = 3; + int d = 4; + int e = 5; + int f = 6; + int g = 7; + int h = 8; + int i = 9; + int j = 10; + { + sum s(x()); + BOOST_TEST(s.get() == 0); + } + { + sum s(x(a)); + BOOST_TEST(s.get() == 1); + } + { + sum s(x(a, b)); + BOOST_TEST(s.get() == 3); + } + { + sum s(x(a, b, c)); + BOOST_TEST(s.get() == 6); + } + { + sum s(x(a, b, c, d)); + BOOST_TEST(s.get() == 10); + } + { + sum s(x(a, b, c, d, e)); + BOOST_TEST(s.get() == 15); + } + { + sum s(x(a, b, c, d, e, f)); + BOOST_TEST(s.get() == 21); + } + { + sum s(x(a, b, c, d, e, f, g)); + BOOST_TEST(s.get() == 28); + } + { + sum s(x(a, b, c, d, e, f, g, h)); + BOOST_TEST(s.get() == 36); + } + { + sum s(x(a, b, c, d, e, f, g, h, i)); + BOOST_TEST(s.get() == 45); + } + { + sum s(x(a, b, c, d, e, f, g, h, i, j)); + BOOST_TEST(s.get() == 55); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/functional/factory/test/value_factory_args.cpp b/src/boost/libs/functional/factory/test/value_factory_args.cpp new file mode 100644 index 00000000..0288fcd5 --- /dev/null +++ b/src/boost/libs/functional/factory/test/value_factory_args.cpp @@ -0,0 +1,40 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/functional/value_factory.hpp> +#include <boost/core/lightweight_test.hpp> + +class sum { +public: + explicit sum(int a = 0, int b = 0, int c = 0, int d = 0, + int e = 0, int f = 0, int g = 0, int h = 0, + int i = 0, int j = 0, int k = 0, int l = 0) + : value_(a + b + c + d + e + f + g + h + i + j + k + l) { } + + int get() const { + return value_; + } + +private: + int value_; +}; + +int main() +{ + sum s(boost::value_factory<sum>()(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)); + BOOST_TEST(s.get() == 78); + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/functional/factory/test/value_factory_move.cpp b/src/boost/libs/functional/factory/test/value_factory_move.cpp new file mode 100644 index 00000000..c0dd37fc --- /dev/null +++ b/src/boost/libs/functional/factory/test/value_factory_move.cpp @@ -0,0 +1,54 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include <boost/functional/value_factory.hpp> +#include <boost/core/lightweight_test.hpp> + +class arg { +public: + explicit arg(int n) + : value_(n) { } + + arg(arg&& a) + : value_(a.value_) { } + + int get() const { + return value_; + } + +private: + int value_; +}; + +class sum { +public: + explicit sum(arg&& a1, arg&& a2) + : value_(a1.get() + a2.get()) { } + + int get() const { + return value_; + } + +private: + int value_; +}; + +int main() +{ + sum s(boost::value_factory<sum>()(arg(1), arg(2))); + BOOST_TEST(s.get() == 3); + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/functional/forward/index.html b/src/boost/libs/functional/forward/index.html new file mode 100644 index 00000000..18030298 --- /dev/null +++ b/src/boost/libs/functional/forward/index.html @@ -0,0 +1,15 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> + <head> + <meta http-equiv="refresh" content="0; URL=doc/html/index.html"> + </head> + <body> + Automatic redirection failed, click this + <a href="doc/html/index.html">link</a> <hr> + <p>© Copyright Tobias Schwinger, 2009</p> + <p>Distributed under the Boost Software License, Version 1.0. (See + accompanying file <a href="../../../LICENSE_1_0.txt"> + LICENSE_1_0.txt</a> or copy at + <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p> + </body> +</html> diff --git a/src/boost/libs/functional/forward/test/Jamfile b/src/boost/libs/functional/forward/test/Jamfile new file mode 100644 index 00000000..9169456d --- /dev/null +++ b/src/boost/libs/functional/forward/test/Jamfile @@ -0,0 +1,17 @@ + +# (C) Copyright Tobias Schwinger +# +# Use modification and distribution are subject to the boost Software License, +# Version 1.0. (See http:/\/www.boost.org/LICENSE_1_0.txt). + +import testing ; + +project forward-tests + ; + +test-suite functional/forward + : + [ run forward_adapter.cpp ] + [ run lightweight_forward_adapter.cpp ] + ; + diff --git a/src/boost/libs/functional/forward/test/forward_adapter.cpp b/src/boost/libs/functional/forward/test/forward_adapter.cpp new file mode 100644 index 00000000..0c5e0c36 --- /dev/null +++ b/src/boost/libs/functional/forward/test/forward_adapter.cpp @@ -0,0 +1,135 @@ +/*============================================================================= + Copyright (c) 2007 Tobias Schwinger + + Use modification and distribution are subject to the Boost Software + License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +==============================================================================*/ + +#include <boost/config.hpp> + +#ifdef BOOST_MSVC +# pragma warning(disable: 4244) // no conversion warnings, please +#endif + +#include <boost/core/lightweight_test.hpp> +#include <boost/functional/forward_adapter.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include <boost/blank.hpp> +#include <boost/noncopyable.hpp> + +#include <memory> + +template <class Base = boost::blank> +class test_func : public Base +{ + int val; +public: + test_func(int v) : val(v) { } + + template<class B> + test_func(test_func<B> const & that) + : val(that.val) + { } + + template<class B> friend class test_func; + + int operator()(int & l, int const & r) const + { + return l=r+val; + } + long operator()(int & l, int const & r) + { + return -(l=r+val); + } + char operator()(int& l, int& r) + { + return l=r+val; + } + + template <typename Sig> + struct result + { + typedef void type; + }; + + // ensure result_of argument types are what's expected + // note: this is *not* how client code should look like + template <class Self> + struct result< Self const(int&,int const&) > { typedef int type; }; + + template <class Self> + struct result< Self(int&,int const&) > { typedef long type; }; + + template <class Self> + struct result< Self(int&,int&) > { typedef char type; }; +}; + +enum { int_, long_, char_ }; + +int type_of(int) { return int_; } +int type_of(long) { return long_; } +int type_of(char) { return char_; } + +int main() +{ + { + using boost::is_same; + using boost::result_of; + typedef boost::forward_adapter< test_func<> > f; + + // lvalue,rvalue + BOOST_TEST(( is_same< + result_of< f(int&, int) >::type, long >::value )); + BOOST_TEST(( is_same< + result_of< f const (int&, int) >::type, int >::value )); + // lvalue,const lvalue + BOOST_TEST(( is_same< + result_of< f(int&, int const &) >::type, long >::value )); + BOOST_TEST(( is_same< + result_of< f const (int&, int const &) >::type, int >::value )); + // lvalue,lvalue + BOOST_TEST(( is_same< + result_of< f(int&, int&) >::type, char >::value )); + // result_of works differently for C++11 here, so compare + // with using it against test_func. + BOOST_TEST(( is_same< + result_of< f const (int&, int&) >::type, + result_of< test_func<> const (int&, int&)>::type >::value )); + } + + { + using boost::noncopyable; + using boost::forward_adapter; + + int x = 0; + test_func<noncopyable> f(7); + forward_adapter< test_func<> > func(f); + forward_adapter< test_func<noncopyable> & > func_ref(f); + forward_adapter< test_func<noncopyable> & > const func_ref_c(f); + forward_adapter< test_func<> const > func_c(f); + forward_adapter< test_func<> > const func_c2(f); + forward_adapter< test_func<noncopyable> const & > func_c_ref(f); + + BOOST_TEST( type_of( func(x,1) ) == long_ ); + BOOST_TEST( type_of( func_ref(x,1) ) == long_ ); + BOOST_TEST( type_of( func_ref_c(x,1) ) == long_ ); + BOOST_TEST( type_of( func_c(x,1) ) == int_ ); + BOOST_TEST( type_of( func_c2(x,1) ) == int_ ); + BOOST_TEST( type_of( func_c_ref(x,1) ) == int_ ); + BOOST_TEST( type_of( func(x,x) ) == char_ ); + + BOOST_TEST( func(x,1) == -8 ); + BOOST_TEST( func_ref(x,1) == -8 ); + BOOST_TEST( func_ref_c(x,1) == -8 ); + BOOST_TEST( func_c(x,1) == 8 ); + BOOST_TEST( func_c2(x,1) == 8 ); + BOOST_TEST( func_c_ref(x,1) == 8 ); + } + + return boost::report_errors(); +} + + diff --git a/src/boost/libs/functional/forward/test/lightweight_forward_adapter.cpp b/src/boost/libs/functional/forward/test/lightweight_forward_adapter.cpp new file mode 100644 index 00000000..b89c92ad --- /dev/null +++ b/src/boost/libs/functional/forward/test/lightweight_forward_adapter.cpp @@ -0,0 +1,135 @@ +/*============================================================================= + Copyright (c) 2007 Tobias Schwinger + + Use modification and distribution are subject to the Boost Software + License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt). +==============================================================================*/ + +#include <boost/config.hpp> + +#ifdef BOOST_MSVC +# pragma warning(disable: 4244) // no conversion warnings, please +#endif + +#include <boost/core/lightweight_test.hpp> +#include <boost/functional/lightweight_forward_adapter.hpp> + +#include <boost/type_traits/is_same.hpp> + +#include <boost/blank.hpp> +#include <boost/noncopyable.hpp> + +#include <memory> + +template <class Base = boost::blank> +class test_func : public Base +{ + int val; +public: + test_func(int v) : val(v) { } + + template<class B> + test_func(test_func<B> const & that) + : val(that.val) + { } + + template<class B> friend class test_func; + + int operator()(int & l, int const & r) const + { + return l=r+val; + } + long operator()(int & l, int const & r) + { + return -(l=r+val); + } + char operator()(int & l, int & r) + { + return l=r+val; + } + + template <typename Sig> + struct result + { + typedef void type; + }; + + // ensure result_of argument types are what's expected + // note: this is *not* how client code should look like + template <class Self> + struct result< Self const(int&,int const&) > { typedef int type; }; + + template <class Self> + struct result< Self(int&,int const&) > { typedef long type; }; + + template <class Self> + struct result< Self(int&,int&) > { typedef char type; }; +}; + +enum { int_, long_, char_ }; + +int type_of(int) { return int_; } +int type_of(long) { return long_; } +int type_of(char) { return char_; } + +int main() +{ + { + using boost::is_same; + using boost::result_of; + typedef boost::lightweight_forward_adapter< test_func<> > f; + typedef boost::reference_wrapper<int> ref; + typedef boost::reference_wrapper<int const> cref; + + // lvalue,rvalue + BOOST_TEST(( is_same< + result_of< f(ref, int) >::type, long >::value )); + BOOST_TEST(( is_same< + result_of< f const (ref, int) >::type, int >::value )); + // lvalue,const lvalue + BOOST_TEST(( is_same< + result_of< f(ref, cref) >::type, long >::value )); + BOOST_TEST(( is_same< + result_of< f const (ref, cref) >::type, int >::value )); + // lvalue,lvalue + BOOST_TEST(( is_same< + result_of< f(ref, ref) >::type, char >::value )); + // result_of works differently for C++11 here, so compare + // with using it against test_func. + BOOST_TEST(( is_same< + result_of< f const (ref, ref) >::type, + result_of< test_func<> const (int&, int&) >::type >::value )); + } + { + using boost::noncopyable; + using boost::lightweight_forward_adapter; + + int v = 0; boost::reference_wrapper<int> x(v); + test_func<noncopyable> f(7); + lightweight_forward_adapter< test_func<> > func(f); + lightweight_forward_adapter< test_func<noncopyable> & > func_ref(f); + lightweight_forward_adapter< test_func<noncopyable> & > const func_ref_c(f); + lightweight_forward_adapter< test_func<> const > func_c(f); + lightweight_forward_adapter< test_func<> > const func_c2(f); + lightweight_forward_adapter< test_func<noncopyable> const & > func_c_ref(f); + + BOOST_TEST( type_of( func(x,1) ) == long_ ); + BOOST_TEST( type_of( func_ref(x,1) ) == long_ ); + BOOST_TEST( type_of( func_ref_c(x,1) ) == long_ ); + BOOST_TEST( type_of( func_c(x,1) ) == int_ ); + BOOST_TEST( type_of( func_c2(x,1) ) == int_ ); + BOOST_TEST( type_of( func_c_ref(x,1) ) == int_ ); + BOOST_TEST( type_of( func(x,x) ) == char_ ); + + BOOST_TEST( func(x,1) == -8 ); + BOOST_TEST( func_ref(x,1) == -8 ); + BOOST_TEST( func_ref_c(x,1) == -8 ); + BOOST_TEST( func_c(x,1) == 8 ); + BOOST_TEST( func_c2(x,1) == 8 ); + BOOST_TEST( func_c_ref(x,1) == 8 ); + } + + return boost::report_errors(); +} + diff --git a/src/boost/libs/functional/function_traits.html b/src/boost/libs/functional/function_traits.html new file mode 100644 index 00000000..c0ce5108 --- /dev/null +++ b/src/boost/libs/functional/function_traits.html @@ -0,0 +1,233 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> + +<html> +<head> + <meta http-equiv="Content-Language" content="en-us"> + <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> + + <title>Boost Function Object Adapter Library</title> +</head> + +<body bgcolor="#FFFFFF" text="#000000"> + <table border="1" bgcolor="#007F7F" cellpadding="2" summary=""> + <tr> + <td bgcolor="#FFFFFF"><img src="../../boost.png" alt= + "boost.png (6897 bytes)" width="277" height="86"></td> + + <td><a href="../../index.htm"><font face="Arial" color= + "#FFFFFF"><big>Home</big></font></a></td> + + <td><a href="../libraries.htm"><font face="Arial" color= + "#FFFFFF"><big>Libraries</big></font></a></td> + + <td><a href="http://www.boost.org/people/people.htm"><font face="Arial" color= + "#FFFFFF"><big>People</big></font></a></td> + + <td><a href="http://www.boost.org/more/faq.htm"><font face="Arial" color= + "#FFFFFF"><big>FAQ</big></font></a></td> + + <td><a href="../../more/index.htm"><font face="Arial" color= + "#FFFFFF"><big>More</big></font></a></td> + </tr> + </table> + + <h1>Function Object Traits</h1> + + <p>The header <a href="../../boost/functional.hpp">functional.hpp</a> + provides two traits class templates for functions and function objects:</p> + + <table border="1" summary=""> + <tr> + <th>Type</th> + + <th>Contents</th> + + <th>Description</th> + </tr> + + <tr> + <td valign="top" rowspan="4"> + <tt>template <typename T><br> + struct unary_traits</tt></td> + + <td valign="top"><tt>function_type</tt></td> + + <td valign="top">The type of the function or function object itself + (i.e., <tt>T</tt>).</td> + </tr> + + <tr> + <td valign="top"><tt>param_type</tt></td> + + <td valign="top">The type that should be used to pass the function or + function object as a parameter.</td> + </tr> + + <tr> + <td valign="top"><tt>result_type</tt></td> + + <td valign="top">The type returned by the function or function + object.</td> + </tr> + + <tr> + <td valign="top"><tt>argument_type</tt></td> + + <td valign="top">The type of the argument to the function or function + object.</td> + </tr> + + <tr> + <td valign="top" rowspan="5"> + <tt>template <typename T><br> + struct binary_traits</tt></td> + + <td valign="top"><tt>function_type</tt></td> + + <td valign="top">The type of the function or function object itself + (i.e., <tt>T</tt>).</td> + </tr> + + <tr> + <td valign="top"><tt>param_type</tt></td> + + <td valign="top">The type that should be used to pass the function or + function object as a parameter.</td> + </tr> + + <tr> + <td valign="top"><tt>result_type</tt></td> + + <td valign="top">The type returned by the function or function + object.</td> + </tr> + + <tr> + <td valign="top"><tt>first_argument_type</tt></td> + + <td valign="top">The type of the first argument to the function or + function object.</td> + </tr> + + <tr> + <td valign="top"><tt>second_argument_type</tt></td> + + <td valign="top">The type of the second argument to the function or + function object.</td> + </tr> + </table> + + <h3>Usage</h3> + + <p><tt>unary_traits</tt> should be instantiated with either a function + taking a single parameter, or an adaptable unary function object (i.e., a + class derived from <tt>std::unary_function</tt> or one which provides the + same typedefs). (See §20.3.1 in the C++ Standard.)</p> + + <p><tt>binary_traits</tt> should be instantiated with either a function + taking two parameters, or an adaptable binary function object (i.e., a + class derived from <tt>std::binary_function</tt> or one which provides the + same typedefs). (See §20.3.1 in the C++ Standard.)</p> + + <p>The most common usage of these templates is in function object adapters, + thus allowing them to adapt plain functions as well as function objects. + You can do this by wherever you would normally write, for example,</p> + + <blockquote> + <pre> +typename Operation::argument_type +</pre> + </blockquote> + + <p>simply writing</p> + + <blockquote> + <pre> +typename boost::unary_traits<Operation>::argument_type +</pre> + </blockquote> + + <p>instead.</p> + + <h3>Additional Types Defined</h3> + + <p>In addition to the standard result and argument typedefs, these traits + templates define two additional types.</p> + + <h4><tt>function_type</tt></h4> + + <p>This is the type of the function or function object, and can be used in + declarations such as</p> + + <blockquote> + <pre> +template <class Predicate> +class unary_negate : // ... +{ + // ... + private: + <strong>typename unary_traits<Predicate>::function_type</strong> pred; +}; +</pre> + </blockquote> + + <p>If this typedef were not provided, it would not be possible to declare + <tt>pred</tt> in a way that would allow <tt>unary_negate</tt> to be + instantiated with a function type (see the C++ Standard §14.3.1 + ¶3).</p> + + <h4><tt>param_type</tt></h4> + + <p>This is a type suitable for passing the function or function object as a + parameter to another function. For example,</p> + + <blockquote> + <pre> +template <class Predicate> +class unary_negate : // ... +{ + public: + explicit unary_negate(<strong>typename unary_traits<Predicate>::param_type</strong> x) + : + pred(x) + {} + // ... +}; +</pre> + </blockquote> + + <p>Function objects are passed by reference to const; function pointers are + passed by value.</p> + + <h3>Limitations</h3> + + <p>This library uses these traits within all function object adapters, + theoretically rendering <tt>ptr_fun</tt> obsolete. However, third party + adapters probably won't take advantage of this mechanism, and so + <tt>ptr_fun</tt> may still be required. Accordingly, this library also + provides <a href="ptr_fun.html">improved versions of the standard function + pointer adapters</a>.</p> + + <p>These traits templates will also not work with compilers that fail to + support partial specialisation of templates. With these compilers, the + traits templates can only be instantiated with adaptable function objects, + thus requiring <tt>ptr_fun</tt> to be used, even with the function object + adapters in this library.</p> + <hr> + + <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src= + "../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional" + height="31" width="88"></a></p> + + <p>Revised + <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->02 + December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38510" --></p> + + <p><i>Copyright © 2000 Cadenza New Zealand Ltd.</i></p> + + <p><i>Distributed under the Boost Software License, Version 1.0. (See + accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or + copy at <a href= + "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p> +</body> +</html> diff --git a/src/boost/libs/functional/hash/index.html b/src/boost/libs/functional/hash/index.html new file mode 100644 index 00000000..12b57579 --- /dev/null +++ b/src/boost/libs/functional/hash/index.html @@ -0,0 +1,16 @@ + +<!-- +Copyright 2005-2007 Daniel James. +Distributed under the Boost Software License, Version 1.0. (See accompanying +file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +--> + +<html> +<head> + <meta http-equiv="refresh" content="0; URL=../../../doc/html/hash.html"> +</head> +<body> +Automatic redirection failed, please go to +<a href="../../../doc/html/hash.html">../../../doc/html/hash.html</a> +</body> +</html> diff --git a/src/boost/libs/functional/index.html b/src/boost/libs/functional/index.html new file mode 100644 index 00000000..f4315a0b --- /dev/null +++ b/src/boost/libs/functional/index.html @@ -0,0 +1,263 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> + +<html> +<head> + <meta http-equiv="Content-Language" content="en-us"> + <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> + <meta name="GENERATOR" content="Microsoft FrontPage 6.0"> + <meta name="ProgId" content="FrontPage.Editor.Document"> + + <title>Boost Function Object Adapter Library</title> +</head> + +<body bgcolor="#FFFFFF" text="#000000"> + <table border="1" bgcolor="#007F7F" cellpadding="2" summary=""> + <tr> + <td bgcolor="#FFFFFF"><img src="../../boost.png" alt= + "boost.png (6897 bytes)" width="277" height="86"></td> + + <td><a href="../../index.htm"><font face="Arial" color= + "#FFFFFF"><big>Home</big></font></a></td> + + <td><a href="../libraries.htm"><font face="Arial" color= + "#FFFFFF"><big>Libraries</big></font></a></td> + + <td><a href="http://www.boost.org/people/people.htm"><font face="Arial" color= + "#FFFFFF"><big>People</big></font></a></td> + + <td><a href="http://www.boost.org/more/faq.htm"><font face="Arial" color= + "#FFFFFF"><big>FAQ</big></font></a></td> + + <td><a href="../../more/index.htm"><font face="Arial" color= + "#FFFFFF"><big>More</big></font></a></td> + </tr> + </table> + + <h1>Improved Function Object Adapters</h1> + + <p>The header <a href="../../boost/functional.hpp">functional.hpp</a> + provides enhancements to the function object adapters specified in the C++ + Standard Library (sections 20.3.5, through to 20.3.8). The enhancements are + principally possible due to two changes:</p> + + <ol> + <li>We use the Boost <tt><a href= + "../utility/call_traits.htm">call_traits</a></tt> templates to avoid the + problem of <a href="binders.html#refref">references to references</a>, + and to improve the efficiency of <a href="mem_fun.html#args">parameter + passing</a>.</li> + + <li>We use two <a href="function_traits.html">function object traits</a> + class templates to avoid the need for <tt><a href= + "ptr_fun.html">ptr_fun</a></tt> with the adapters in this library.</li> + </ol> + + <h3>Contents</h3> + + <p>The header contains the following function and class templates:</p> + + <table border="1" cellpadding="5" summary=""> + <tr> + <th align="left"><a href="function_traits.html">Function object + traits</a></th> + + <td valign="top"><tt>unary_traits<br> + binary_traits</tt></td> + + <td valign="top">Used to determine the types of function objects' and + functions' arguments. Eliminate the necessity for + <tt>ptr_fun</tt>.</td> + </tr> + + <tr> + <th align="left"><a href="negators.html">Negators</a></th> + + <td valign="top"><tt>unary_negate<br> + binary_negate<br> + not1<br> + not2</tt></td> + + <td valign="top">Based on section 20.3.5 of the standard.</td> + </tr> + + <tr> + <th align="left"><a href="binders.html">Binders</a></th> + + <td valign="top"><tt>binder1st<br> + binder2nd<br> + bind1st<br> + bind2nd</tt></td> + + <td valign="top">Based on section 20.3.6 of the standard.</td> + </tr> + + <tr> + <th align="left"><a href="ptr_fun.html">Adapters for pointers to + functions</a></th> + + <td valign="top"><tt>pointer_to_unary_function<br> + pointer_to_binary_function<br> + ptr_fun</tt></td> + + <td valign="top">Based on section 20.3.7 of the standard. Not required + for use with this library since the binders and negators can adapt + functions, but may be needed with third party adapters.</td> + </tr> + + <tr> + <th align="left"><a href="mem_fun.html">Adapters for pointers to member + functions</a></th> + + <td valign="top"><tt>mem_fun_t<br> + mem_fun1_t<br> + const_mem_fun_t<br> + const_mem_fun1_t<br> + mem_fun_ref_t<br> + mem_fun1_ref_t<br> + const_mem_fun_ref_t<br> + const_mem_fun1_ref_t<br> + mem_fun<br> + mem_fun_ref</tt></td> + + <td valign="top">Based on section 20.3.8 of the standard.</td> + </tr> + </table> + + <h3>Usage</h3> + + <p>Using these adapters should be pretty much the same as using the + standard function object adapters; the only differences are that you need + to write <tt>boost::</tt> instead of <tt>std::</tt>, and that you will get + fewer headaches.</p> + + <p>For example, suppose you had a <tt>Person</tt> class that contained a + <tt>set_name</tt> function:</p> + + <blockquote> + <pre> +class Person +{ + public: + void set_name(const std::string &name); + // ... +}; +</pre> + </blockquote> + + <p>You could rename a bunch of people in a collection, <tt>c</tt>, by + writing</p> + + <blockquote> + <pre> +std::for_each(c.begin(), c.end(), + boost::bind2nd(boost::mem_fun_ref(&Person::set_name), "Fred")); +</pre> + </blockquote> + + <p>If the standard adapters had been used instead then this code would + normally fail to compile, because <tt>set_name</tt> takes a reference + argument. Refer to the comments in the <a href="binders.html#refref">binder + documentation</a> to explain why this is so.</p> + + <h3>Compiler Compatibility</h3> + + <p>The header and <a href="test/function_test.cpp">test program</a> have been + compiled with the following compilers:</p> + + <table border="1" cellpadding="5" summary=""> + <tr> + <th>Compiler</th> + + <th>Comments</th> + </tr> + + <tr> + <td valign="top">Borland C++Builder 4 Update 2</td> + + <td valign="top">No known issues.</td> + </tr> + + <tr> + <td valign="top">Borland C++ 5.5</td> + + <td valign="top">No known issues.</td> + </tr> + + <tr> + <td valign="top">g++ 2.95.2</td> + + <td valign="top">No known issues.</td> + </tr> + + <tr> + <td valign="top">Microsoft Visual C++ Service Pack 3</td> + + <td valign="top"> + Compiler lacks partial specialisation, so this library offers little + more than is provided by the standard adapters: + + <ul> + <li>The <tt>call_traits</tt> mechanism is unable to prevent + references to references, and so the adapters in this library will + be usable in fewer situations.</li> + + <li>The <tt>function_traits</tt> mechanism is unable to determine + the argument and result types of functions, therefore + <tt>ptr_fun</tt> continues to be required to adapt functions.</li> + </ul> + </td> + </tr> + </table> + + <h3>Future Directions</h3> + + <p>This library's primary focus is to solve the problem of references to + references while maintaining as much compatibility as possible with the + standard library. This allows you to use the techniques you read about in + books and magazines with many of today's compilers.</p> + + <p>In the longer term, even better solutions are likely:</p> + + <ol> + <li>Several Boost members are working on expression template libraries. + These will allow a more natural syntax for combining and adapting + functions. As this is a new technology, it may be some time before it has + matured and is widely supported by major compilers but shows great + promise. In the meantime, the functional.hpp library fills the gap.</li> + + <li>The Standard Committee has recognised the problem of references to + references occurring during template instantiation and has moved to fix + the standard (see the <a href= + "http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#106">C++ + standard core language active issues list</a>).</li> + </ol> + + <h3>Author</h3> + + <p><a href="http://www.boost.org/people/mark_rodgers.htm">Mark Rodgers</a></p> + + <h3>Acknowledgements</h3> + + <p>Thanks to <a href="http://www.boost.org/people/john_maddock.htm">John Maddock</a> for + suggesting the mechanism that allowed the function objects traits to work + correctly. <a href="http://www.boost.org/people/jens_maurer.htm">Jens Maurer</a> provided + invaluable feedback during the <a href= + "http://www.boost.org/more/formal_review_process.htm">formal review process</a>.</p> + <hr> + + <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src= + "../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional" + height="31" width="88"></a></p> + + <p>Revised + <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->02 + December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38510" --></p> + + <p><i>Copyright © 2000 Cadenza New Zealand Ltd.</i></p> + + <p><i>Distributed under the Boost Software License, Version 1.0. (See + accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or + copy at <a href= + "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p> +</body> +</html> diff --git a/src/boost/libs/functional/mem_fun.html b/src/boost/libs/functional/mem_fun.html new file mode 100644 index 00000000..54d3aee3 --- /dev/null +++ b/src/boost/libs/functional/mem_fun.html @@ -0,0 +1,201 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> + +<html> +<head> + <meta http-equiv="Content-Language" content="en-us"> + <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> + + <title>Boost Function Object Adapter Library</title> +</head> + +<body bgcolor="#FFFFFF" text="#000000"> + <table border="1" bgcolor="#007F7F" cellpadding="2" summary=""> + <tr> + <td bgcolor="#FFFFFF"><img src="../../boost.png" alt= + "boost.png (6897 bytes)" width="277" height="86"></td> + + <td><a href="../../index.htm"><font face="Arial" color= + "#FFFFFF"><big>Home</big></font></a></td> + + <td><a href="../libraries.htm"><font face="Arial" color= + "#FFFFFF"><big>Libraries</big></font></a></td> + + <td><a href="http://www.boost.org/people/people.htm"><font face="Arial" color= + "#FFFFFF"><big>People</big></font></a></td> + + <td><a href="http://www.boost.org/more/faq.htm"><font face="Arial" color= + "#FFFFFF"><big>FAQ</big></font></a></td> + + <td><a href="../../more/index.htm"><font face="Arial" color= + "#FFFFFF"><big>More</big></font></a></td> + </tr> + </table> + + <h1>Member Function Adapters</h1> + + <p>The header <a href="../../boost/functional.hpp">functional.hpp</a> + includes improved versions of the full range of member function adapters + from the the C++ Standard Library (§20.3.8):</p> + + <ul> + <li><tt>mem_fun_t</tt></li> + + <li><tt>mem_fun1_t</tt></li> + + <li><tt>const_mem_fun_t</tt></li> + + <li><tt>const_mem_fun1_t</tt></li> + + <li><tt>mem_fun_ref_t</tt></li> + + <li><tt>mem_fun1_ref_t</tt></li> + + <li><tt>const_mem_fun_ref_t</tt></li> + + <li><tt>const_mem_fun1_ref_t</tt></li> + </ul> + + <p>as well as the corresponding overloaded helper functions</p> + + <ul> + <li><tt>mem_fun</tt></li> + + <li><tt>mem_fun_ref</tt></li> + </ul> + + <p>The following changes have been made to the adapters as specified in the + Standard:</p> + + <ul> + <li>The <tt>first_argument_type</tt> typedef has been corrected for the + <tt>const_</tt> family of member function adapters (see <a href= + "#firstarg">below</a>).</li> + + <li>The argument passed to <tt>mem_fun1_t</tt> and its variants is passed + using the <tt>call_traits::param_type</tt> for the member function's + argument type.</li> + </ul> + + <h3 id="firstarg">first_argument_type</h3> + + <p>The standard specifies <tt>const_mem_fun1_t</tt>, for example, like + this:</p> + + <blockquote> + <pre> +template <class S, class T, class A> class const_mem_fun1_t + : public binary_function<<strong>T*</strong>, A, S> { +public: + explicit const_mem_fun1_t(S (T::*p)(A) const); + S operator()(<strong>const T*</strong> p, A x) const; +}; +</pre> + </blockquote> + + <p>Note that the first argument to <tt>binary_function</tt> is <tt>T*</tt> + despite the fact that the first argument to <tt>operator()</tt> is actually + of type <tt><em>const</em> T*</tt>.</p> + + <p>Does this matter? Well, consider what happens when we write</p> + + <blockquote> + <pre> +struct Foo { void bar(int) const; }; +const Foo *cp = new Foo; +std::bind1st(std::mem_fun(&Foo::bar), cp); +</pre> + </blockquote> + + <p>We have created a <tt>const_mem_fun1_t</tt> object which will + effectively contain the following</p> + + <blockquote> + <pre> +typedef Foo* first_argument_type; +</pre> + </blockquote> + + <p>The <tt>bind1st</tt> will then create a <tt>binder1st</tt> object that + will use this <tt>typedef</tt> as the type of a member which will be + initialised with <tt>cp</tt>. In other words, we will need to initialise a + <tt>Foo*</tt> member with a <tt>const Foo*</tt> pointer! Clearly this + is not possible, so to implement this your Standard Library vendor will + have had to cast away the constness of <tt>cp</tt>, probably within the + body of <tt>bind1st</tt>.</p> + + <p>This hack will not suffice with the improved <a href= + "binders.html">binders</a> in this library, so we have had to provide + corrected versions of the member function adapters as well.</p> + + <h3 id="args">Argument Types</h3> + + <p>The standard defines <tt>mem_fun1_t</tt>, for example, like this + (§20.3.8 ¶2):</p> + + <blockquote> + <pre> +template <class S, class T, class A> class mem_fun1_t + : public binary_function<T*, A, S> { +public: + explicit mem_fun1_t(S (T::*p)(<strong>A</strong>)); + S operator()(T* p, <strong>A</strong> x) const; +}; +</pre> + </blockquote> + + <p>Note that the second argument to <tt>operator()</tt> is exactly the same + type as the argument to the member function. If this is a value type, the + argument will be passed by value and copied twice.</p> + + <p>However, if we were to try and eliminate this inefficiency by instead + declaring the argument as <tt>const A&</tt>, then if A were a + reference type, we would have a reference to a reference, which is + currently illegal (but see <a href= + "http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#106">C++ core + language issue number 106)</a></p> + + <p>So the way in which we want to declare the second argument for + <tt>operator()</tt> depends on whether or not the member function's + argument is a reference. If it is a reference, we want to declare it simply + as <tt>A</tt>; if it is a value we want to declare it as + <tt>const A&</tt>.</p> + + <p>The Boost <a href="../utility/call_traits.htm">call_traits</a> class + template contains a <tt>param_type</tt> typedef, which uses partial + specialisation to make precisely this decision. By declaring the + <tt>operator()</tt> as</p> + + <blockquote> + <pre> +S operator()(T* p, typename call_traits<A>::param_type x) const +</pre> + </blockquote> + + <p>we achieve the desired result - we improve efficiency without generating + references to references.</p> + + <h3>Limitations</h3> + + <p>The call traits template used to realise some improvements relies on + partial specialisation, so these improvements are only available on + compilers that support that feature. With other compilers, the argument + passed to the member function (in the <tt>mem_fun1_t</tt> family) will + always be passed by reference, thus generating the possibility of + references to references.</p> + <hr> + + <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src= + "../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional" + height="31" width="88"></a></p> + + <p>Revised + <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->02 December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38510" --></p> + + <p><i>Copyright © 2000 Cadenza New Zealand Ltd.</i></p> + + <p><i>Distributed under the Boost Software License, Version 1.0. (See + accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or + copy at <a href= + "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p> +</body> +</html> diff --git a/src/boost/libs/functional/meta/explicit-failures-markup.xml b/src/boost/libs/functional/meta/explicit-failures-markup.xml new file mode 100644 index 00000000..ea9b3239 --- /dev/null +++ b/src/boost/libs/functional/meta/explicit-failures-markup.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright 2017-2018 Daniel James + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or copy at + http://www.boost.org/LICENSE_1_0.txt) +--> +<explicit-failures-markup> + <!-- functional/factory --> + <library name="functional/factory"> + <mark-expected-failures> + <test name="factory_with_allocator"/> + <toolset name="borland-*"/> + <note author="Tobias Schwinger"> + Probably broken const conversion with that compiler. + </note> + </mark-expected-failures> + </library> + + <!-- functional/forward --> + <library name="functional/foward"> + <mark-unusable> + <toolset name="msvc-7.0*"/> + <toolset name="msvc-7.1*"/> + <toolset name="sun-5.*"/> + <toolset name="vacpp*"/> + <toolset name="borland-*"/> + <note author="Tobias Schwinger"> + This compiler is currently not supported. + </note> + </mark-unusable> + </library> +</explicit-failures-markup> diff --git a/src/boost/libs/functional/meta/libraries.json b/src/boost/libs/functional/meta/libraries.json new file mode 100644 index 00000000..c9d7a3b9 --- /dev/null +++ b/src/boost/libs/functional/meta/libraries.json @@ -0,0 +1,64 @@ +[ + { + "key": "functional", + "boost-version": "1.16.0", + "name": "Functional", + "authors": [ + "Mark Rodgers" + ], + "description": "The Boost.Function library contains a family of class templates that are function object wrappers.", + "category": [ + "Function-objects" + ] + }, + { + "key": "functional/factory", + "boost-version": "1.43.0", + "name": "Functional/Factory", + "authors": [ + "Glen Fernandes", + "Tobias Schwinger" + ], + "maintainers": [ + "Glen Fernandes <glenjofe -at- gmail.com>", + "Tobias Schwinger <tschwinger -at- isonews2.com>" + ], + "description": "Function object templates for dynamic and static object creation", + "documentation": "factory/", + "category": [ + "Function-objects" + ] + }, + { + "key": "functional/forward", + "boost-version": "1.43.0", + "name": "Functional/Forward", + "authors": [ + "Tobias Schwinger" + ], + "maintainers": [ + "Tobias Schwinger <tschwinger -at- isonews2.com>" + ], + "description": "Adapters to allow generic function objects to accept arbitrary arguments", + "documentation": "forward/", + "category": [ + "Function-objects" + ] + }, + { + "key": "functional/overloaded_function", + "boost-version": "1.50.0", + "name": "Functional/Overloaded Function", + "authors": [ + "Lorenzo Caminiti" + ], + "maintainers": [ + "Lorenzo Caminiti <lorcaminiti -at- gmail.com>" + ], + "description": "Overload different functions into a single function object.", + "documentation": "overloaded_function/", + "category": [ + "Function-objects" + ] + } +] diff --git a/src/boost/libs/functional/negators.html b/src/boost/libs/functional/negators.html new file mode 100644 index 00000000..5af3c54a --- /dev/null +++ b/src/boost/libs/functional/negators.html @@ -0,0 +1,158 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> + +<html> +<head> + <meta http-equiv="Content-Language" content="en-us"> + <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> + + <title>Boost Function Object Adapter Library</title> +</head> + +<body bgcolor="#FFFFFF" text="#000000"> + <table border="1" bgcolor="#007F7F" cellpadding="2" summary=""> + <tr> + <td bgcolor="#FFFFFF"><img src="../../boost.png" alt= + "boost.png (6897 bytes)" width="277" height="86"></td> + + <td><a href="../../index.htm"><font face="Arial" color= + "#FFFFFF"><big>Home</big></font></a></td> + + <td><a href="../libraries.htm"><font face="Arial" color= + "#FFFFFF"><big>Libraries</big></font></a></td> + + <td><a href="http://www.boost.org/people/people.htm"><font face="Arial" color= + "#FFFFFF"><big>People</big></font></a></td> + + <td><a href="http://www.boost.org/more/faq.htm"><font face="Arial" color= + "#FFFFFF"><big>FAQ</big></font></a></td> + + <td><a href="../../more/index.htm"><font face="Arial" color= + "#FFFFFF"><big>More</big></font></a></td> + </tr> + </table> + + <h1>Negators</h1> + + <p>The header <a href="../../boost/functional.hpp">functional.hpp</a> + provides enhanced versions of both the negator adapters from the C++ + Standard Library (§20.3.5):</p> + + <ul> + <li><tt>unary_negate</tt></li> + + <li><tt>binary_negate</tt></li> + </ul> + + <p>As well as the corresponding helper functions</p> + + <ul> + <li><tt>not1</tt></li> + + <li><tt>not2</tt></li> + </ul> + + <p>However, the negators in this library improve on the standard versions + in two ways:</p> + + <ul> + <li>They use <a href="function_traits.html">function object traits</a> to + avoid the need for <tt>ptr_fun</tt> when negating a function rather than + an adaptable function object.</li> + + <li>They use Boost <a href= + "../utility/call_traits.htm">call traits</a> to determine the best + way to declare their arguments and pass them through to the adapted + function (see <a href="#arguments">below</a>).</li> + </ul> + + <h3>Usage</h3> + + <p>Usage is identical to the standard negators. For example,</p> + + <blockquote> + <pre> +bool bad(const Foo &foo) { ... } +... +std::vector<Foo> c; +... +std::find_if(c.begin(), c.end(), boost::not1(bad)); +</pre> + </blockquote> + + <h3 id="arguments">Argument Types</h3> + + <p>The C++ Standard (§20.3.5) defines unary negate like this (binary + negate is similar):</p> + + <blockquote> + <pre> +template <class Predicate> + class unary_negate + : public unary_function<typename Predicate::argument_type,bool> { +public: + explicit unary_negate(const Predicate& pred); + bool operator()(<strong>const typename Predicate::argument_type&</strong> x) const; +}; +</pre> + </blockquote> + + <p>Note that if the Predicate's <tt>argument_type</tt> is a reference, the + type of <tt>operator()</tt>'s argument would be a reference to a reference. + Currently this is illegal in C++ (but see the <a href= + "http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#106">C++ + standard core language active issues list</a>).</p> + + <p>However, if we instead defined <tt>operator()</tt> to accept Predicate's + argument_type unmodified, this would be needlessly inefficient if it were a + value type; the argument would be copied twice - once when calling + <tt>unary_negate</tt>'s <tt>operator()</tt>, and again when + <tt>operator()</tt> called the adapted function.</p> + + <p>So how we want to declare the argument for <tt>operator()</tt> depends + on whether or not the Predicate's <tt>argument_type</tt> is a reference. If + it is a reference, we want to declare it simply as <tt>argument_type</tt>; + if it is a value we want to declare it as + <tt>const argument_type&</tt>.</p> + + <p>The Boost <a href="../utility/call_traits.htm">call_traits</a> class + template contains a <tt>param_type</tt> typedef, which uses partial + specialisation to make precisely this decision. If we were to declare + <tt>operator()</tt> as</p> + + <blockquote> + <pre> +bool operator()(typename call_traits<typename Predicate::argument_type>::param_type x) const +</pre> + </blockquote> + + <p>the desired result would be achieved - we would eliminate references to + references without loss of efficiency. In fact, the actual declaration is + slightly more complicated because of the use of function object traits, but + the effect remains the same.</p> + + <h3>Limitations</h3> + + <p>Both the function object traits and call traits used to realise these + improvements rely on partial specialisation, these improvements are only + available on compilers that support that feature. With other compilers, the + negators in this library behave very much like those in the Standard - + <tt>ptr_fun</tt> will be required to adapt functions, and references to + references will not be avoided.</p> + <hr> + + <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src= + "../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional" + height="31" width="88"></a></p> + + <p>Revised + <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->02 + December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38510" --></p> + + <p><i>Copyright © 2000 Cadenza New Zealand Ltd.</i></p> + + <p><i>Distributed under the Boost Software License, Version 1.0. (See + accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or + copy at <a href= + "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p> +</body> +</html> diff --git a/src/boost/libs/functional/overloaded_function/index.html b/src/boost/libs/functional/overloaded_function/index.html new file mode 100644 index 00000000..00b33623 --- /dev/null +++ b/src/boost/libs/functional/overloaded_function/index.html @@ -0,0 +1,15 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<html> + <head> + <meta http-equiv="refresh" content="0; URL=doc/html/index.html"> + </head> + <body> + Automatic redirection failed, click this + <a href="doc/html/index.html">link</a> <hr> + <p>© Copyright Lorenzo Caminiti, 2009-2012</p> + <p>Distributed under the Boost Software License, Version 1.0 (see + accompanying file <a href="../../../LICENSE_1_0.txt"> + LICENSE_1_0.txt</a> or a copy at + <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p> + </body> +</html> diff --git a/src/boost/libs/functional/overloaded_function/test/Jamfile.v2 b/src/boost/libs/functional/overloaded_function/test/Jamfile.v2 new file mode 100644 index 00000000..3871ee57 --- /dev/null +++ b/src/boost/libs/functional/overloaded_function/test/Jamfile.v2 @@ -0,0 +1,16 @@ + +# Copyright (C) 2009-2012 Lorenzo Caminiti +# Distributed under the Boost Software License, Version 1.0 +# (see accompanying file LICENSE_1_0.txt or a copy at +# http://www.boost.org/LICENSE_1_0.txt) +# Home at http://www.boost.org/libs/functional/overloaded_function + +import testing ; + +# Sun does not automatically detect type-of emulation (force it). +project : requirements <toolset>sun:<define>BOOST_TYPEOF_EMULATION ; + +run functor.cpp ; +run make_decl.cpp ; +run make_call.cpp ; + diff --git a/src/boost/libs/functional/overloaded_function/test/functor.cpp b/src/boost/libs/functional/overloaded_function/test/functor.cpp new file mode 100644 index 00000000..2df52e79 --- /dev/null +++ b/src/boost/libs/functional/overloaded_function/test/functor.cpp @@ -0,0 +1,34 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/functional/overloaded_function + +#include "identity.hpp" +#include <boost/functional/overloaded_function.hpp> +#include <boost/core/lightweight_test.hpp> + +int main() { + //[identity_calls + BOOST_TEST(identity_s("abc") == "abc"); + BOOST_TEST(identity_i(123) == 123); + BOOST_TEST(identity_d(1.23) == 1.23); + //] + + //[identity_functor + boost::overloaded_function< + const std::string& (const std::string&) + , int (int) + , double (double) + > identity(identity_s, identity_i, identity_d); + + // All calls via single `identity` function. + BOOST_TEST(identity("abc") == "abc"); + BOOST_TEST(identity(123) == 123); + BOOST_TEST(identity(1.23) == 1.23); + //] + + return boost::report_errors(); +} + diff --git a/src/boost/libs/functional/overloaded_function/test/identity.hpp b/src/boost/libs/functional/overloaded_function/test/identity.hpp new file mode 100644 index 00000000..51344297 --- /dev/null +++ b/src/boost/libs/functional/overloaded_function/test/identity.hpp @@ -0,0 +1,29 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/functional/overloaded_function + +#ifndef IDENTITY_HPP_ +#define IDENTITY_HPP_ + +//[identity_typeof +#include <boost/typeof/std/string.hpp> // No need to register `boost::function`. +//] +#include <boost/function.hpp> +#include <string> + +//[identity_decls +const std::string& identity_s(const std::string& x) // Function (as pointer). + { return x; } + +int identity_i_impl(int x) { return x; } +int (&identity_i)(int) = identity_i_impl; // Function reference. + +double identity_d_impl(double x) { return x; } +boost::function<double (double)> identity_d = identity_d_impl; // Functor. +//] + +#endif // #include guard + diff --git a/src/boost/libs/functional/overloaded_function/test/make_call.cpp b/src/boost/libs/functional/overloaded_function/test/make_call.cpp new file mode 100644 index 00000000..89ffab06 --- /dev/null +++ b/src/boost/libs/functional/overloaded_function/test/make_call.cpp @@ -0,0 +1,27 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/functional/overloaded_function + +#include "identity.hpp" +#include <boost/functional/overloaded_function.hpp> +#include <boost/core/lightweight_test.hpp> + +//[identity_make_checks +template<typename F> +void check(F identity) { + BOOST_TEST(identity("abc") == "abc"); + BOOST_TEST(identity(123) == 123); + BOOST_TEST(identity(1.23) == 1.23); +} +//] + +int main() { + //[identity_make_call + check(boost::make_overloaded_function(identity_s, identity_i, identity_d)); + //] + return boost::report_errors(); +} + diff --git a/src/boost/libs/functional/overloaded_function/test/make_decl.cpp b/src/boost/libs/functional/overloaded_function/test/make_decl.cpp new file mode 100644 index 00000000..ea3bac65 --- /dev/null +++ b/src/boost/libs/functional/overloaded_function/test/make_decl.cpp @@ -0,0 +1,24 @@ + +// Copyright (C) 2009-2012 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 +// (see accompanying file LICENSE_1_0.txt or a copy at +// http://www.boost.org/LICENSE_1_0.txt) +// Home at http://www.boost.org/libs/functional/overloaded_function + +#include "identity.hpp" +#include <boost/functional/overloaded_function.hpp> +#include <boost/typeof/typeof.hpp> +#include <boost/core/lightweight_test.hpp> + +int main() { + //[identity_make_decl + BOOST_AUTO(identity, boost::make_overloaded_function( + identity_s, identity_i, identity_d)); + + BOOST_TEST(identity("abc") == "abc"); + BOOST_TEST(identity(123) == 123); + BOOST_TEST(identity(1.23) == 1.23); + //] + return boost::report_errors(); +} + diff --git a/src/boost/libs/functional/ptr_fun.html b/src/boost/libs/functional/ptr_fun.html new file mode 100644 index 00000000..a8ba2659 --- /dev/null +++ b/src/boost/libs/functional/ptr_fun.html @@ -0,0 +1,158 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> + +<html> +<head> + <meta http-equiv="Content-Language" content="en-us"> + <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> + + <title>Boost Function Object Adapter Library</title> +</head> + +<body bgcolor="#FFFFFF" text="#000000"> + <table border="1" bgcolor="#007F7F" cellpadding="2" summary=""> + <tr> + <td bgcolor="#FFFFFF"><img src="../../boost.png" alt= + "boost.png (6897 bytes)" width="277" height="86"></td> + + <td><a href="../../index.htm"><font face="Arial" color= + "#FFFFFF"><big>Home</big></font></a></td> + + <td><a href="../libraries.htm"><font face="Arial" color= + "#FFFFFF"><big>Libraries</big></font></a></td> + + <td><a href="http://www.boost.org/people/people.htm"><font face="Arial" color= + "#FFFFFF"><big>People</big></font></a></td> + + <td><a href="http://www.boost.org/more/faq.htm"><font face="Arial" color= + "#FFFFFF"><big>FAQ</big></font></a></td> + + <td><a href="../../more/index.htm"><font face="Arial" color= + "#FFFFFF"><big>More</big></font></a></td> + </tr> + </table> + + <h1>Function Pointer Adapters</h1> + + <p>The header <a href="../../boost/functional.hpp">functional.hpp</a> + provides enhanced versions of both the function pointer adapters from the + C++ Standard Library (§20.3.7):</p> + + <ul> + <li><tt>pointer_to_unary_function</tt></li> + + <li><tt>pointer_to_binary_function</tt></li> + </ul> + + <p>As well as the corresponding helper function template:</p> + + <ul> + <li><tt>ptr_fun</tt></li> + </ul> + + <p>However, you should not need to use the adapters in conjunction with the + adapters in this library due to our use of <a href= + "function_traits.html">function object traits</a>. You will however need to + use them if your implementation fails to work properly with our traits + classes (due to lack if partial specialisation), or if you wish to use a + function object adapter from a third party.</p> + + <h3>Usage</h3> + + <p>If you need to use these adapters, usage is identical to the standard + function pointer adapters. For example,</p> + + <blockquote> + <pre> +bool bad(std::string foo) { ... } +... +std::vector<std::string> c; +... +std::vector<std::string>::iterator it + = std::find_if(c.begin(), c.end(), std::not1(boost::ptr_fun(bad))); +</pre> + </blockquote> + + <p>Note however that this library contains enhanced <a href= + "negators.html">negators</a> that support function object traits, so the + line above could equally be written</p> + + <blockquote> + <pre> +std::vector<std::string>::iterator it + = std::find_if(c.begin(), c.end(), boost::not1(bad)); +</pre> + </blockquote> + + <h3>Argument Types</h3> + + <p>The standard defines <tt>pointer_to_unary_function</tt> like this + (§20.3.8 ¶2):</p> + + <blockquote> + <pre> +template <class Arg, class Result> +class pointer_to_unary_function : public unary_function<Arg, Result> { +public: + explicit pointer_to_unary_function(Result (* f)(<strong>Arg</strong>)); + Result operator()(<strong>Arg</strong> x) const; +}; +</pre> + </blockquote> + + <p>Note that the argument to <tt>operator()</tt> is exactly the same type + as the argument to the wrapped function. If this is a value type, the + argument will be passed by value and copied twice. + <tt>pointer_to_binary_function</tt> has a similar problem.</p> + + <p>However, if we were to try and eliminate this inefficiency by instead + declaring the argument as <tt>const Arg&</tt>, then if Arg were a + reference type, we would have a reference to a reference, which is + currently illegal (but see <a href= + "http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#106">C++ core + language issue number 106)</a></p> + + <p>So the way in which we want to declare the argument for + <tt>operator()</tt> depends on whether or not the wrapped function's + argument is a reference. If it is a reference, we want to declare it simply + as <tt>Arg</tt>; if it is a value we want to declare it as + <tt>const Arg&</tt>.</p> + + <p>The Boost <a href="../utility/call_traits.htm">call_traits</a> class + template contains a <tt>param_type</tt> typedef, which uses partial + specialisation to make precisely this decision. By declaring the + <tt>operator()</tt> as</p> + + <blockquote> + <pre> +Result operator()(typename call_traits<Arg>::param_type x) const +</pre> + </blockquote> + + <p>we achieve the desired result - we improve efficiency without generating + references to references.</p> + + <h3>Limitations</h3> + + <p>The call traits template used to realise this improvement relies on + partial specialisation, so this improvement is only available on compilers + that support that feature. With other compilers, the argument passed to the + function will always be passed by reference, thus generating the + possibility of references to references.</p> + <hr> + + <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src= + "../../doc/images/valid-html401.png" alt="Valid HTML 4.01 Transitional" + height="31" width="88"></a></p> + + <p>Revised + <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->02 + December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38510" --></p> + + <p><i>Copyright © 2000 Cadenza New Zealand Ltd.</i></p> + + <p><i>Distributed under the Boost Software License, Version 1.0. (See + accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or + copy at <a href= + "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p> +</body> +</html> diff --git a/src/boost/libs/functional/sublibs b/src/boost/libs/functional/sublibs new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/boost/libs/functional/sublibs diff --git a/src/boost/libs/functional/test/Jamfile.v2 b/src/boost/libs/functional/test/Jamfile.v2 new file mode 100644 index 00000000..dbe379c0 --- /dev/null +++ b/src/boost/libs/functional/test/Jamfile.v2 @@ -0,0 +1,9 @@ +#~ Copyright Rene Rivera 2008 +#~ Distributed under the Boost Software License, Version 1.0. +#~ (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +import testing ; + +test-suite functional : + [ run function_test.cpp ] + ; diff --git a/src/boost/libs/functional/test/function_test.cpp b/src/boost/libs/functional/test/function_test.cpp new file mode 100644 index 00000000..318a7504 --- /dev/null +++ b/src/boost/libs/functional/test/function_test.cpp @@ -0,0 +1,334 @@ +// ------------------------------------------------------------------------------ +// Copyright (c) 2000 Cadenza New Zealand Ltd +// Distributed under the Boost Software License, Version 1.0. (See accompany- +// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// ------------------------------------------------------------------------------ +// Tests for the Boost functional.hpp header file +// +// Note that functional.hpp relies on partial specialisation to be +// effective. If your compiler lacks this feature, very few of the +// tests would compile, and so have been excluded from the test. +// ------------------------------------------------------------------------------ +// $Id$ +// ------------------------------------------------------------------------------ +// $Log$ +// Revision 1.3 2006/12/02 13:57:32 andreas_huber69 +// Fixed license & copyright issues. +// +// From Mark Rodgers Fri Dec 1 12:59:14 2006 +// X-Apparently-To: ahd6974-boostorg -at- yahoo.com via 68.142.206.160; Fri, 01 Dec 2006 12:59:41 -0800 +// X-Originating-IP: [195.112.4.54] +// Return-Path: <mark.rodgers -at- cadenza.co.nz> +// Authentication-Results: mta550.mail.mud.yahoo.com from=cadenza.co.nz; domainkeys=neutral (no sig) +// Received: from 195.112.4.54 (EHLO smtp.nildram.co.uk) (195.112.4.54) by mta550.mail.mud.yahoo.com with SMTP; Fri, 01 Dec 2006 12:59:40 -0800 +// Received: from snagglepuss.cadenza.co.nz (81-6-246-87.dyn.gotadsl.co.uk [81.6.246.87]) by smtp.nildram.co.uk (Postfix) with ESMTP id D32EA2B6D8C for <ahd6974-boostorg -at- yahoo.com>; Fri, 1 Dec 2006 20:59:35 +0000 (GMT) +// Received: from penfold.cadenza.co.nz ([192.168.55.56]) by snagglepuss.cadenza.co.nz with esmtp (Exim 4.63) (envelope-from <mark.rodgers -at- cadenza.co.nz>) id J9M4Y9-0009TO-9K for ahd6974-boostorg -at- yahoo.com; Fri, 01 Dec 2006 20:58:57 +0000 +// Message-ID: <457097A2.1090305@cadenza.co.nz> +// Date: Fri, 01 Dec 2006 20:59:14 +0000 +// From: "Mark Rodgers" <mark.rodgers -at- cadenza.co.nz> +// User-Agent: Thunderbird 1.5.0.8 (Macintosh/20061025) +// MIME-Version: 1.0 +// To: ahd6974-boostorg -at- yahoo.com [Edit - Delete] +// Subject: Re: [boost] Reminder: Need your permission to correct license & copyright issues +// References: <379990.36007.qm@web33507.mail.mud.yahoo.com> +// In-Reply-To: <379990.36007.qm@web33507.mail.mud.yahoo.com> +// Content-Type: text/plain; charset=ISO-8859-1; format=flowed +// Content-Transfer-Encoding: 7bit +// Content-Length: 812 +// Gidday Andreas +// +// Sure that's fine. I'm happy for you to do 1, 2 and 3. +// +// Regards +// Mark +// +// Andreas Huber wrote: +// > Hello Mark +// > +// > Quite a while ago it was decided that every file that goes into the +// > 1.34 release of the Boost distribution (www.boost.org) needs uniform +// > license and copyright information. For more information please see: +// > +// > <http://www.boost.org/more/license_info.html> +// > +// > You are receiving this email because several files you contributed +// > lack such information or have an old license: +// > +// > boost/functional/functional.hpp +// > boost/libs/functional/binders.html +// > boost/libs/functional/function_test.cpp +// > boost/libs/functional/function_traits.html +// > boost/libs/functional/index.html +// > boost/libs/functional/mem_fun.html +// > boost/libs/functional/negators.html +// > boost/libs/functional/ptr_fun.html +// > boost/people/mark_rodgers.htm +// > +// > I therefore kindly ask you to grant the permission to do the +// > following: +// > +// > 1. For the files above that already have a license text (all except +// > mark_rodgers.htm), replace the license text with: +// > +// > "Distributed under the Boost Software License, Version 1.0. (See +// > accompanying file LICENSE_1_0.txt or copy at +// > http://www.boost.org/LICENSE_1_0.txt)" +// > +// > 2. For the file that does not yet have a license and copyright +// > (mark_rodgers.htm) add the same license text as under 1. and add the +// > following copyright: +// > +// > "(c) Copyright Mark Rodgers 2000" +// > +// > 3. (Optional) I would also want to convert all HTML files to conform +// > the HTML 4.01 Standard by running them through HTML Tidy, see +// > <http://tidy.sf.net> +// > +// > It would be great if you could grant me permission to do 1 & 2 and +// > optionally also 3. +// > +// > Thank you! +// > +// > Regards, +// > +// > Andreas Huber +// > +// +// Revision 1.2 2001/09/22 11:52:24 johnmaddock +// Intel C++ fixes: no void return types supported. +// +// Revision 1.1.1.1 2000/07/07 16:04:18 beman +// 1.16.1 initial CVS checkin +// +// Revision 1.3 2000/06/26 09:44:01 mark +// Updated following feedback from Jens Maurer. +// +// Revision 1.2 2000/05/17 08:31:45 mark +// Added extra tests now that function traits work correctly. +// For compilers with no support for partial specialisation, +// excluded tests that won't work. +// +// Revision 1.1 2000/05/07 09:14:41 mark +// Initial revision +// ------------------------------------------------------------------------------ + +// To demonstrate what the boosted function object adapters do for +// you, try compiling with USE_STD defined. This will endeavour to +// use the standard function object adapters, but is likely to result +// in numerous errors due to the fact that you cannot have references +// to references. +#ifdef USE_STD +#include <functional> +#define boost std +#else +#include <boost/functional.hpp> +#endif + +#include <algorithm> +#include <iostream> +#include <iterator> +#include <string> +#include <vector> + +class Person +{ + public: + Person() {} + Person(const char *n) : name(n) {} + + const std::string &get_name() const { return name; } + void print(std::ostream &os) const { os << name << " "; } + void set_name(const std::string &n) { name = n; std::cout << name << " "; } + std::string clear_name() { std::string ret = name; name = ""; return ret; } + void do_something(int) const {} + + bool is_fred() const { return name == "Fred"; } + + private: + std::string name; +}; + +namespace +{ + bool is_equal(const std::string &s1, const std::string &s2) + { + return s1 == s2; + } + + bool is_betty(const std::string &s) + { + return s == "Betty"; + } + + void do_set_name(Person *p, const std::string &name) + { + p->set_name(name); + } + + void do_set_name_ref(Person &p, const std::string &name) + { + p.set_name(name); + } +} + +int main() +{ + std::vector<Person> v1; + v1.push_back("Fred"); + v1.push_back("Wilma"); + v1.push_back("Barney"); + v1.push_back("Betty"); + + const std::vector<Person> cv1(v1.begin(), v1.end()); + + std::vector<std::string> v2; + v2.push_back("Fred"); + v2.push_back("Wilma"); + v2.push_back("Barney"); + v2.push_back("Betty"); + + Person person; + Person &r = person; + + Person fred("Fred"); + Person wilma("Wilma"); + Person barney("Barney"); + Person betty("Betty"); + std::vector<Person*> v3; + v3.push_back(&fred); + v3.push_back(&wilma); + v3.push_back(&barney); + v3.push_back(&betty); + + const std::vector<Person*> cv3(v3.begin(), v3.end()); + std::vector<const Person*> v3c(v3.begin(), v3.end()); + + std::ostream &os = std::cout; + +#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(__ICL) + // unary_traits, unary_negate + std::transform(v2.begin(), v2.end(), + std::ostream_iterator<bool>(std::cout, " "), + boost::not1(is_betty)); + + std::cout << '\n'; + std::transform(v1.begin(), v1.end(), + std::ostream_iterator<bool>(std::cout, " "), + boost::not1(boost::mem_fun_ref(&Person::is_fred))); + + // binary_traits, binary_negate + std::cout << '\n'; + std::transform(v2.begin(), v2.end(), + std::ostream_iterator<bool>(std::cout, " "), + boost::bind1st(boost::not2(is_equal), "Betty")); + + std::cout << '\n'; + std::transform(v2.begin(), v2.end(), + std::ostream_iterator<bool>(std::cout, " "), + boost::bind2nd(boost::not2(is_equal), "Betty")); + + // pointer_to_unary_function + std::cout << '\n'; + std::transform(v2.begin(), v2.end(), + std::ostream_iterator<bool>(std::cout, " "), + boost::not1(boost::ptr_fun(is_betty))); + + // binary_traits, bind1st, bind2nd + std::cout << '\n'; + std::transform(v2.begin(), v2.end(), + std::ostream_iterator<bool>(std::cout, " "), + boost::bind1st(is_equal, "Betty")); + + std::cout << '\n'; + std::transform(v2.begin(), v2.end(), + std::ostream_iterator<bool>(std::cout, " "), + boost::bind2nd(is_equal, "Betty")); + + // pointer_to_binary_function, bind1st + std::cout << '\n'; + std::for_each(v2.begin(), v2.end(), boost::bind1st(boost::ptr_fun(do_set_name), &person)); + + std::cout << '\n'; + std::for_each(v2.begin(), v2.end(), boost::bind1st(boost::ptr_fun(do_set_name_ref), person)); + + std::cout << '\n'; + std::for_each(v2.begin(), v2.end(), boost::bind1st(boost::ptr_fun(do_set_name_ref), r)); + + // binary_traits + std::cout << '\n'; + std::for_each(v2.begin(), v2.end(), boost::bind1st(do_set_name, &person)); + + std::cout << '\n'; + std::for_each(v2.begin(), v2.end(), boost::bind1st(do_set_name_ref, person)); + + std::cout << '\n'; + std::for_each(v2.begin(), v2.end(), boost::bind1st(do_set_name_ref, r)); +#endif + + // const_mem_fun_t + std::cout << '\n'; + std::transform(v3.begin(), v3.end(), + std::ostream_iterator<std::string>(std::cout, " "), + boost::mem_fun(&Person::get_name)); + + std::cout << '\n'; + std::transform(cv3.begin(), cv3.end(), + std::ostream_iterator<std::string>(std::cout, " "), + boost::mem_fun(&Person::get_name)); + + std::cout << '\n'; + std::transform(v3c.begin(), v3c.end(), + std::ostream_iterator<std::string>(std::cout, " "), + boost::mem_fun(&Person::get_name)); + + // const_mem_fun_ref_t + std::cout << '\n'; + std::transform(v1.begin(), v1.end(), + std::ostream_iterator<std::string>(std::cout, " "), + boost::mem_fun_ref(&Person::get_name)); + + std::cout << '\n'; + std::transform(cv1.begin(), cv1.end(), + std::ostream_iterator<std::string>(std::cout, " "), + boost::mem_fun_ref(&Person::get_name)); + +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + // const_mem_fun1_t, bind2nd + std::cout << '\n'; + std::for_each(v3.begin(), v3.end(), boost::bind2nd(boost::mem_fun(&Person::print), std::cout)); + + std::cout << '\n'; + std::for_each(v3.begin(), v3.end(), boost::bind2nd(boost::mem_fun(&Person::print), os)); + + // const_mem_fun1_ref_t, bind2nd + std::cout << '\n'; + std::for_each(v1.begin(), v1.end(), boost::bind2nd(boost::mem_fun_ref(&Person::print), std::cout)); + + std::cout << '\n'; + std::for_each(v1.begin(), v1.end(), boost::bind2nd(boost::mem_fun_ref(&Person::print), os)); + + // mem_fun1_t, bind1st + std::cout << '\n'; + std::for_each(v2.begin(), v2.end(), boost::bind1st(boost::mem_fun(&Person::set_name), &person)); + + // mem_fun1_ref_t, bind1st + std::cout << '\n'; + std::for_each(v2.begin(), v2.end(), boost::bind1st(boost::mem_fun_ref(&Person::set_name), person)); + + std::cout << '\n'; + std::for_each(v2.begin(), v2.end(), boost::bind1st(boost::mem_fun_ref(&Person::set_name), r)); +#endif + + // mem_fun_t + std::cout << '\n'; + std::transform(v3.begin(), v3.end(), std::ostream_iterator<std::string>(std::cout, " "), + boost::mem_fun(&Person::clear_name)); + + // mem_fun_ref_t + std::cout << '\n'; + std::transform(v1.begin(), v1.end(), std::ostream_iterator<std::string>(std::cout, " "), + boost::mem_fun_ref(&Person::clear_name)); + + std::cout << '\n'; + return 0; +} |