mirror of
https://github.com/boostorg/function.git
synced 2025-07-19 07:32:07 +02:00
function_base.hpp:
- Remove safe_bool conversion and operator! from class function_base function_template.hpp: - Add safe_bool conversion and operator! - operator! returns bool, not safe_bool (Peter Dimov) reference.html: - Document above change [SVN r15356]
This commit is contained in:
@ -17,8 +17,6 @@
|
|||||||
{
|
{
|
||||||
<b>typedef</b> <em>implementation-defined</em> safe_bool;
|
<b>typedef</b> <em>implementation-defined</em> safe_bool;
|
||||||
<a href="#empty"><b>bool</b> empty() <b>const</b></a>;
|
<a href="#empty"><b>bool</b> empty() <b>const</b></a>;
|
||||||
<a href="#bool"><b>operator</b> safe_bool() <b>const</b></a>;
|
|
||||||
<a href="#not">safe_bool <b>operator!</b>() <b>const</b></a>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// For <i>N</i> in [0, <i>MAX_ARGS</i>]
|
// For <i>N</i> in [0, <i>MAX_ARGS</i>]
|
||||||
@ -66,6 +64,10 @@
|
|||||||
<a href="#functionN_swap"><b>void</b> swap(function<i>N</i><b>&</b>)</a>;
|
<a href="#functionN_swap"><b>void</b> swap(function<i>N</i><b>&</b>)</a>;
|
||||||
<a href="#functionN_clear"><b>void</b> clear()</a>;
|
<a href="#functionN_clear"><b>void</b> clear()</a>;
|
||||||
|
|
||||||
|
<i>// Boolean context</i>
|
||||||
|
<a href="#bool"><b>operator</b> safe_bool() <b>const</b></a>;
|
||||||
|
<a href="#not"><b>bool</b> <b>operator!</b>() <b>const</b></a>;
|
||||||
|
|
||||||
<i>// Invocation</i>
|
<i>// Invocation</i>
|
||||||
<a href="#functionN_call_const">result_type <b>operator</b>()(Arg1 a1, Arg2 a2, <i>...</i>, Arg<i>N</i> a<i>N</i>) <b>const</b></a>;
|
<a href="#functionN_call_const">result_type <b>operator</b>()(Arg1 a1, Arg2 a2, <i>...</i>, Arg<i>N</i> a<i>N</i>) <b>const</b></a>;
|
||||||
};
|
};
|
||||||
@ -146,20 +148,6 @@
|
|||||||
<li><b>Throws</b>: will not throw.</li>
|
<li><b>Throws</b>: will not throw.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p> <a name="bool"><code><b>operator</b> safe_bool() <b>const</b></code></a>
|
|
||||||
<ul>
|
|
||||||
<li><b>Returns</b>: <code>safe_bool</code> equivalent of <code>!<a href="#empty">empty</a>()</code></li>
|
|
||||||
<li><b>Throws</b>: will not throw.</li>
|
|
||||||
<li><b>Notes</b>: The <code>safe_bool</code> type can be used in contexts where a <b>bool</b> is expected (e.g., an <b>if</b> condition); however, implicit conversions (e.g., to <b>int</b>) that can occur with <b>bool</b> are not allowed, eliminating some sources of user error.
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<p> <a name="not"><code>safe_bool <b>operator!</b>() <b>const</b></code></a>
|
|
||||||
<ul>
|
|
||||||
<li><b>Returns</b>: <code>safe_bool</code> equivalent of <code><a href="#empty">empty</a>()</code></li>
|
|
||||||
<li><b>Throws</b>: will not throw.</li>
|
|
||||||
<li><b>Notes</b>: See <a href="#bool"><code>safe_bool</code> conversion</a>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<h2><a name="functionN">Class template <code>function<i>N</i></code></a></h2>
|
<h2><a name="functionN">Class template <code>function<i>N</i></code></a></h2>
|
||||||
<p> Class template <code>function<i>N</i></code> is actually a family of related classes <code>function0</code>, <code>function1</code>, etc., up to some implementation-defined maximum. In this context, <code><i>N</i></code> refers to the number of parameters and <code>f</code> refers to the implicit object parameter.
|
<p> Class template <code>function<i>N</i></code> is actually a family of related classes <code>function0</code>, <code>function1</code>, etc., up to some implementation-defined maximum. In this context, <code><i>N</i></code> refers to the number of parameters and <code>f</code> refers to the implicit object parameter.
|
||||||
|
|
||||||
@ -239,6 +227,19 @@
|
|||||||
<li><b>Postconditions</b>: <code><a href="#empty">empty</a>()</code>.</li>
|
<li><b>Postconditions</b>: <code><a href="#empty">empty</a>()</code>.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<p> <a name="bool"><code><b>operator</b> safe_bool() <b>const</b></code></a>
|
||||||
|
<ul>
|
||||||
|
<li><b>Returns</b>: <code>safe_bool</code> equivalent of <code>!<a href="#empty">empty</a>()</code></li>
|
||||||
|
<li><b>Throws</b>: will not throw.</li>
|
||||||
|
<li><b>Notes</b>: The <code>safe_bool</code> type can be used in contexts where a <b>bool</b> is expected (e.g., an <b>if</b> condition); however, implicit conversions (e.g., to <b>int</b>) that can occur with <b>bool</b> are not allowed, eliminating some sources of user error.
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p> <a name="not"><code><b>bool</b> <b>operator!</b>() <b>const</b></code></a>
|
||||||
|
<ul>
|
||||||
|
<li><b>Returns</b>: <code>this->empty()</code></li>
|
||||||
|
<li><b>Throws</b>: will not throw.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<p> <a name="functionN_call_const"><code> result_type <b>operator</b>()(Arg1 a1, Arg2 a2, <i>...</i>, Arg<i>N</i> a<i>N</i>) <b>const</b>;</code></a>
|
<p> <a name="functionN_call_const"><code> result_type <b>operator</b>()(Arg1 a1, Arg2 a2, <i>...</i>, Arg<i>N</i> a<i>N</i>) <b>const</b>;</code></a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><b>Requires</b>: <code>!<a href="#empty">empty</a>()</code>.</li>
|
<li><b>Requires</b>: <code>!<a href="#empty">empty</a>()</code>.</li>
|
||||||
|
@ -278,25 +278,6 @@ namespace boost {
|
|||||||
detail::function::any_pointer,
|
detail::function::any_pointer,
|
||||||
detail::function::functor_manager_operation_type);
|
detail::function::functor_manager_operation_type);
|
||||||
detail::function::any_pointer functor;
|
detail::function::any_pointer functor;
|
||||||
|
|
||||||
#if (defined __SUNPRO_CC) && (__SUNPRO_CC <= 0x530) && !(defined BOOST_NO_COMPILER_CONFIG)
|
|
||||||
// Sun C++ 5.3 can't handle the safe_bool idiom, so don't use it
|
|
||||||
operator bool () const { return !this->empty(); }
|
|
||||||
#else
|
|
||||||
private:
|
|
||||||
struct dummy {
|
|
||||||
void nonnull() {};
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef void (dummy::*safe_bool)();
|
|
||||||
|
|
||||||
public:
|
|
||||||
operator safe_bool () const
|
|
||||||
{ return (this->empty())? 0 : &dummy::nonnull; }
|
|
||||||
|
|
||||||
safe_bool operator!() const
|
|
||||||
{ return (this->empty())? &dummy::nonnull : 0; }
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Poison comparison between Boost.Function objects (because it is
|
/* Poison comparison between Boost.Function objects (because it is
|
||||||
|
@ -419,6 +419,25 @@ namespace boost {
|
|||||||
invoker = 0;
|
invoker = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if (defined __SUNPRO_CC) && (__SUNPRO_CC <= 0x530) && !(defined BOOST_NO_COMPILER_CONFIG)
|
||||||
|
// Sun C++ 5.3 can't handle the safe_bool idiom, so don't use it
|
||||||
|
operator bool () const { return !this->empty(); }
|
||||||
|
#else
|
||||||
|
private:
|
||||||
|
struct dummy {
|
||||||
|
void nonnull() {};
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void (dummy::*safe_bool)();
|
||||||
|
|
||||||
|
public:
|
||||||
|
operator safe_bool () const
|
||||||
|
{ return (this->empty())? 0 : &dummy::nonnull; }
|
||||||
|
|
||||||
|
bool operator!() const
|
||||||
|
{ return this->empty(); }
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void assign_to_own(const BOOST_FUNCTION_FUNCTION& f)
|
void assign_to_own(const BOOST_FUNCTION_FUNCTION& f)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user