From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/functional/negators.html | 158 ++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 src/boost/libs/functional/negators.html (limited to 'src/boost/libs/functional/negators.html') 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 @@ + + + + + + + + Boost Function Object Adapter Library + + + + + + + + + + + + + + + + + +
+HomeLibrariesPeopleFAQMore
+ +

Negators

+ +

The header functional.hpp + provides enhanced versions of both the negator adapters from the C++ + Standard Library (§20.3.5):

+ + + +

As well as the corresponding helper functions

+ + + +

However, the negators in this library improve on the standard versions + in two ways:

+ + + +

Usage

+ +

Usage is identical to the standard negators. For example,

+ +
+
+bool bad(const Foo &foo) { ... }
+...
+std::vector<Foo> c;
+...
+std::find_if(c.begin(), c.end(), boost::not1(bad));
+
+
+ +

Argument Types

+ +

The C++ Standard (§20.3.5) defines unary negate like this (binary + negate is similar):

+ +
+
+template <class Predicate>
+  class unary_negate
+    : public unary_function<typename Predicate::argument_type,bool> {
+public:
+  explicit unary_negate(const Predicate& pred);
+  bool operator()(const typename Predicate::argument_type& x) const;
+};
+
+
+ +

Note that if the Predicate's argument_type is a reference, the + type of operator()'s argument would be a reference to a reference. + Currently this is illegal in C++ (but see the C++ + standard core language active issues list).

+ +

However, if we instead defined operator() 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 + unary_negate's operator(), and again when + operator() called the adapted function.

+ +

So how we want to declare the argument for operator() depends + on whether or not the Predicate's argument_type is a reference. If + it is a reference, we want to declare it simply as argument_type; + if it is a value we want to declare it as + const argument_type&.

+ +

The Boost call_traits class + template contains a param_type typedef, which uses partial + specialisation to make precisely this decision. If we were to declare + operator() as

+ +
+
+bool operator()(typename call_traits<typename Predicate::argument_type>::param_type x) const
+
+
+ +

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.

+ +

Limitations

+ +

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 - + ptr_fun will be required to adapt functions, and references to + references will not be avoided.

+
+ +

Valid HTML 4.01 Transitional

+ +

Revised + 02 + December, 2006

+ +

Copyright © 2000 Cadenza New Zealand Ltd.

+ +

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)

+ + -- cgit v1.2.3