forked from boostorg/utility
Compare commits
12 Commits
svn-branch
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
|
6a93732f6b | ||
|
58bb88d4bd | ||
|
11d50ecb9f | ||
|
636283d7c2 | ||
|
1df0bf80bc | ||
|
71e78a0081 | ||
|
f7e4b0e399 | ||
|
fb1d2effef | ||
|
94b91e8c92 | ||
|
a4b8043e68 | ||
|
b4a08fc80e | ||
|
9da96d9737 |
68
doc/Jamfile.v2
Normal file
68
doc/Jamfile.v2
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
|
||||||
|
# Copyright John Maddock 2005. 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)
|
||||||
|
|
||||||
|
project : requirements
|
||||||
|
# Path for links to Boost:
|
||||||
|
<xsl:param>boost.root=../../../..
|
||||||
|
|
||||||
|
# Some general style settings:
|
||||||
|
<xsl:param>table.footnote.number.format=1
|
||||||
|
<xsl:param>footnote.number.format=1
|
||||||
|
|
||||||
|
# HTML options first:
|
||||||
|
# Use graphics not text for navigation:
|
||||||
|
<xsl:param>navig.graphics=1
|
||||||
|
# PDF Options:
|
||||||
|
# TOC Generation: this is needed for FOP-0.9 and later:
|
||||||
|
<xsl:param>fop1.extensions=0
|
||||||
|
<xsl:param>xep.extensions=1
|
||||||
|
# TOC generation: this is needed for FOP 0.2, but must not be set to zero for FOP-0.9!
|
||||||
|
<xsl:param>fop.extensions=0
|
||||||
|
# No indent on body text:
|
||||||
|
<xsl:param>body.start.indent=0pt
|
||||||
|
# Margin size:
|
||||||
|
<xsl:param>page.margin.inner=0.5in
|
||||||
|
# Margin size:
|
||||||
|
<xsl:param>page.margin.outer=0.5in
|
||||||
|
# Paper type = A4
|
||||||
|
<xsl:param>paper.type=A4
|
||||||
|
# Yes, we want graphics for admonishments:
|
||||||
|
<xsl:param>admon.graphics=1
|
||||||
|
# Set this one for PDF generation *only*:
|
||||||
|
# default pnd graphics are awful in PDF form,
|
||||||
|
# better use SVG's instead:
|
||||||
|
<format>pdf:<xsl:param>admon.graphics.extension=".svg"
|
||||||
|
<format>pdf:<xsl:param>admon.graphics.path=$(boost-images)/
|
||||||
|
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/libs/utility/doc/html
|
||||||
|
;
|
||||||
|
|
||||||
|
using quickbook ;
|
||||||
|
|
||||||
|
path-constant boost-images : ../../../doc/src/images ;
|
||||||
|
|
||||||
|
xml declval : declval.qbk ;
|
||||||
|
boostbook standalone
|
||||||
|
:
|
||||||
|
declval
|
||||||
|
:
|
||||||
|
# File name of HTML output:
|
||||||
|
<xsl:param>root.filename=declval
|
||||||
|
# How far down we chunk nested sections, basically all of them:
|
||||||
|
<xsl:param>chunk.section.depth=0
|
||||||
|
# Don't put the first section on the same page as the TOC:
|
||||||
|
<xsl:param>chunk.first.sections=0
|
||||||
|
# How far down sections get TOC's
|
||||||
|
<xsl:param>toc.section.depth=1
|
||||||
|
# Max depth in each TOC:
|
||||||
|
<xsl:param>toc.max.depth=1
|
||||||
|
# How far down we go with TOC's
|
||||||
|
<xsl:param>generate.section.toc.level=1
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
104
doc/declval.qbk
Normal file
104
doc/declval.qbk
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
[/
|
||||||
|
/ Copyright (c) 2008 Howard Hinnant
|
||||||
|
/ Copyright (c) 2008 Beman Dawes
|
||||||
|
/ Copyright (c) 2009-20010 Vicente J. Botet Escriba
|
||||||
|
/
|
||||||
|
/ 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)
|
||||||
|
/]
|
||||||
|
|
||||||
|
[article Declval
|
||||||
|
[quickbook 1.5]
|
||||||
|
[authors [Hinnant, Howard]]
|
||||||
|
[authors [Dawes, Beman]]
|
||||||
|
[authors [Botet Escriba, Vicente J.]]
|
||||||
|
[copyright 2008 Howard Hinnant]
|
||||||
|
[copyright 2008 Beman Dawes]
|
||||||
|
[copyright 2009-2010 Vicente J. Botet Escriba]
|
||||||
|
[license
|
||||||
|
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])
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
[/===============]
|
||||||
|
[section Overview]
|
||||||
|
[/===============]
|
||||||
|
|
||||||
|
The motivation for `declval` was introduced in [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2958.html#Value N2958:
|
||||||
|
Moving Swap Forward]. Here follows a rewording of this chapter.
|
||||||
|
|
||||||
|
With the provision of decltype, late-specified return types, and default template-arguments for function templates a
|
||||||
|
new generation of SFINAE patterns will emerge to at least partially compensate the lack of concepts on the C++0x timescale.
|
||||||
|
Using this technique, it is sometimes necessary to obtain an object of a known type in a non-using context, e.g. given the declaration
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
T&& declval(); // not used
|
||||||
|
|
||||||
|
as part of the function template declaration
|
||||||
|
|
||||||
|
template<class To, class From>
|
||||||
|
decltype(static_cast<To>(declval<From>())) convert(From&&);
|
||||||
|
|
||||||
|
or as part of a class template definition
|
||||||
|
|
||||||
|
template<class> class result_of;
|
||||||
|
|
||||||
|
template<class Fn, class... ArgTypes>
|
||||||
|
struct result_of<Fn(ArgTypes...)>
|
||||||
|
{
|
||||||
|
typedef decltype(declval<Fn>()(declval<ArgTypes>()...)) type;
|
||||||
|
};
|
||||||
|
|
||||||
|
The role of the function template declval() is a transformation of a type T into a value without using or evaluating this function.
|
||||||
|
The name is supposed to direct the reader's attention to the fact that the expression `declval<T>()` is an lvalue if and only if
|
||||||
|
T is an lvalue-reference, otherwise an rvalue. To extend the domain of this function we can do a bit better by changing its declaration to
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
typename std::add_rvalue_reference<T>::type declval(); // not used
|
||||||
|
|
||||||
|
which ensures that we can also use cv void as template parameter. The careful reader might have noticed that `declval()`
|
||||||
|
already exists under the name create() as part of the definition of the semantics of the type trait is_convertible in the C==0x standard.
|
||||||
|
|
||||||
|
The provision of a new library component that allows the production of values in unevaluated expressions is considered as
|
||||||
|
important to realize constrained templates in C++0x where concepts are not available.
|
||||||
|
This extremely light-weight function is expected to be part of the daily tool-box of the C++0x programmer.
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
|
||||||
|
[/=================]
|
||||||
|
[section:reference Reference ]
|
||||||
|
[/=================]
|
||||||
|
|
||||||
|
`#include <boost/utility/declval.hpp>`
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
typename add_rvalue_reference<T>::type declval(); //noexcept; // as unevaluated operand
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
|
||||||
|
The library provides the function template declval to simplify the definition of expressions which occur as unevaluated operands.
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
typename add_rvalue_reference<T>::type declval();
|
||||||
|
|
||||||
|
[*Remarks:] If this function is used, the program is ill-formed.
|
||||||
|
|
||||||
|
[*Remarks:] The template parameter T of declval may be an incomplete type.
|
||||||
|
|
||||||
|
[*Example:]
|
||||||
|
|
||||||
|
template <class To, class From>
|
||||||
|
decltype(static_cast<To>(declval<From>())) convert(From&&);
|
||||||
|
|
||||||
|
Declares a function template convert which only participats in overloading if the type From can be explicitly converted to type To.
|
||||||
|
|
||||||
|
[endsect]
|
||||||
|
|
||||||
|
|
||||||
|
|
163
doc/html/declval.html
Normal file
163
doc/html/declval.html
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||||
|
<title>Declval</title>
|
||||||
|
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
|
||||||
|
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
|
||||||
|
<link rel="home" href="declval.html" title="Declval">
|
||||||
|
</head>
|
||||||
|
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||||
|
<table cellpadding="2" width="100%"><tr>
|
||||||
|
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
|
||||||
|
<td align="center"><a href="../../../../index.html">Home</a></td>
|
||||||
|
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
|
||||||
|
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||||
|
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||||
|
<td align="center"><a href="../../../../more/index.htm">More</a></td>
|
||||||
|
</tr></table>
|
||||||
|
<hr>
|
||||||
|
<div class="spirit-nav"></div>
|
||||||
|
<div class="article" lang="en">
|
||||||
|
<div class="titlepage">
|
||||||
|
<div>
|
||||||
|
<div><h2 class="title">
|
||||||
|
<a name="declval"></a>Declval</h2></div>
|
||||||
|
<div><div class="authorgroup">
|
||||||
|
<div class="author"><h3 class="author">
|
||||||
|
<span class="firstname">Howard</span> <span class="surname">Hinnant</span>
|
||||||
|
</h3></div>
|
||||||
|
<div class="author"><h3 class="author">
|
||||||
|
<span class="firstname">Beman</span> <span class="surname">Dawes</span>
|
||||||
|
</h3></div>
|
||||||
|
<div class="author"><h3 class="author">
|
||||||
|
<span class="firstname">Vicente J.</span> <span class="surname">Botet Escriba</span>
|
||||||
|
</h3></div>
|
||||||
|
</div></div>
|
||||||
|
<div><p class="copyright">Copyright © 2008 Howard Hinnant</p></div>
|
||||||
|
<div><p class="copyright">Copyright © 2008 Beman Dawes</p></div>
|
||||||
|
<div><p class="copyright">Copyright © 2009 -2010 Vicente J. Botet Escriba</p></div>
|
||||||
|
<div><div class="legalnotice">
|
||||||
|
<a name="id879409"></a><p>
|
||||||
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||||
|
</p>
|
||||||
|
</div></div>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
<div class="toc">
|
||||||
|
<p><b>Table of Contents</b></p>
|
||||||
|
<dl>
|
||||||
|
<dt><span class="section"><a href="declval.html#declval.overview">Overview</a></span></dt>
|
||||||
|
<dt><span class="section"><a href="declval.html#declval.reference"> Reference </a></span></dt>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
<div class="section" lang="en">
|
||||||
|
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||||
|
<a name="declval.overview"></a><a class="link" href="declval.html#declval.overview" title="Overview">Overview</a>
|
||||||
|
</h2></div></div></div>
|
||||||
|
<p>
|
||||||
|
The motivation for <code class="computeroutput"><span class="identifier">declval</span></code>
|
||||||
|
was introduced in <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2958.html#Value" target="_top">N2958:
|
||||||
|
Moving Swap Forward</a>. Here follows a rewording of this chapter.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
With the provision of decltype, late-specified return types, and default template-arguments
|
||||||
|
for function templates a new generation of SFINAE patterns will emerge to at
|
||||||
|
least partially compensate the lack of concepts on the C++0x timescale. Using
|
||||||
|
this technique, it is sometimes necessary to obtain an object of a known type
|
||||||
|
in a non-using context, e.g. given the declaration
|
||||||
|
</p>
|
||||||
|
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
||||||
|
<span class="identifier">T</span><span class="special">&&</span> <span class="identifier">declval</span><span class="special">();</span> <span class="comment">// not used
|
||||||
|
</span></pre>
|
||||||
|
<p>
|
||||||
|
as part of the function template declaration
|
||||||
|
</p>
|
||||||
|
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">To</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">From</span><span class="special">></span>
|
||||||
|
<span class="identifier">decltype</span><span class="special">(</span><span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">To</span><span class="special">>(</span><span class="identifier">declval</span><span class="special"><</span><span class="identifier">From</span><span class="special">>()))</span> <span class="identifier">convert</span><span class="special">(</span><span class="identifier">From</span><span class="special">&&);</span>
|
||||||
|
</pre>
|
||||||
|
<p>
|
||||||
|
or as part of a class template definition
|
||||||
|
</p>
|
||||||
|
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span><span class="special">></span> <span class="keyword">class</span> <span class="identifier">result_of</span><span class="special">;</span>
|
||||||
|
|
||||||
|
<span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">Fn</span><span class="special">,</span> <span class="keyword">class</span><span class="special">...</span> <span class="identifier">ArgTypes</span><span class="special">></span>
|
||||||
|
<span class="keyword">struct</span> <span class="identifier">result_of</span><span class="special"><</span><span class="identifier">Fn</span><span class="special">(</span><span class="identifier">ArgTypes</span><span class="special">...)></span>
|
||||||
|
<span class="special">{</span>
|
||||||
|
<span class="keyword">typedef</span> <span class="identifier">decltype</span><span class="special">(</span><span class="identifier">declval</span><span class="special"><</span><span class="identifier">Fn</span><span class="special">>()(</span><span class="identifier">declval</span><span class="special"><</span><span class="identifier">ArgTypes</span><span class="special">>()...))</span> <span class="identifier">type</span><span class="special">;</span>
|
||||||
|
<span class="special">};</span>
|
||||||
|
</pre>
|
||||||
|
<p>
|
||||||
|
The role of the function template declval() is a transformation of a type T
|
||||||
|
into a value without using or evaluating this function. The name is supposed
|
||||||
|
to direct the reader's attention to the fact that the expression <code class="computeroutput"><span class="identifier">declval</span><span class="special"><</span><span class="identifier">T</span><span class="special">>()</span></code> is
|
||||||
|
an lvalue if and only if T is an lvalue-reference, otherwise an rvalue. To
|
||||||
|
extend the domain of this function we can do a bit better by changing its declaration
|
||||||
|
to
|
||||||
|
</p>
|
||||||
|
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
||||||
|
<span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">add_rvalue_reference</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">declval</span><span class="special">();</span> <span class="comment">// not used
|
||||||
|
</span></pre>
|
||||||
|
<p>
|
||||||
|
which ensures that we can also use cv void as template parameter. The careful
|
||||||
|
reader might have noticed that <code class="computeroutput"><span class="identifier">declval</span><span class="special">()</span></code> already exists under the name create() as
|
||||||
|
part of the definition of the semantics of the type trait is_convertible in
|
||||||
|
the C==0x standard.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
The provision of a new library component that allows the production of values
|
||||||
|
in unevaluated expressions is considered as important to realize constrained
|
||||||
|
templates in C++0x where concepts are not available. This extremely light-weight
|
||||||
|
function is expected to be part of the daily tool-box of the C++0x programmer.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="section" lang="en">
|
||||||
|
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||||
|
<a name="declval.reference"></a><a class="link" href="declval.html#declval.reference" title="Reference"> Reference </a>
|
||||||
|
</h2></div></div></div>
|
||||||
|
<p>
|
||||||
|
<code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">/</span><span class="identifier">declval</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>
|
||||||
|
</p>
|
||||||
|
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
|
||||||
|
|
||||||
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">></span>
|
||||||
|
<span class="keyword">typename</span> <span class="identifier">add_rvalue_reference</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">declval</span><span class="special">();</span> <span class="comment">//noexcept; // as unevaluated operand
|
||||||
|
</span>
|
||||||
|
<span class="special">}</span> <span class="comment">// namespace boost
|
||||||
|
</span></pre>
|
||||||
|
<p>
|
||||||
|
The library provides the function template declval to simplify the definition
|
||||||
|
of expressions which occur as unevaluated operands.
|
||||||
|
</p>
|
||||||
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">></span>
|
||||||
|
<span class="keyword">typename</span> <span class="identifier">add_rvalue_reference</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">declval</span><span class="special">();</span>
|
||||||
|
</pre>
|
||||||
|
<p>
|
||||||
|
<span class="bold"><strong>Remarks:</strong></span> If this function is used, the program
|
||||||
|
is ill-formed.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<span class="bold"><strong>Remarks:</strong></span> The template parameter T of declval
|
||||||
|
may be an incomplete type.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<span class="bold"><strong>Example:</strong></span>
|
||||||
|
</p>
|
||||||
|
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">To</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">From</span><span class="special">></span>
|
||||||
|
<span class="identifier">decltype</span><span class="special">(</span><span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">To</span><span class="special">>(</span><span class="identifier">declval</span><span class="special"><</span><span class="identifier">From</span><span class="special">>()))</span> <span class="identifier">convert</span><span class="special">(</span><span class="identifier">From</span><span class="special">&&);</span>
|
||||||
|
</pre>
|
||||||
|
<p>
|
||||||
|
Declares a function template convert which only participats in overloading
|
||||||
|
if the type From can be explicitly converted to type To.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||||
|
<td align="left"><p><small>Last revised: September 16, 2010 at 16:19:10 GMT</small></p></td>
|
||||||
|
<td align="right"><div class="copyright-footer"></div></td>
|
||||||
|
</tr></table>
|
||||||
|
<hr>
|
||||||
|
<div class="spirit-nav"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
@@ -13,6 +13,12 @@
|
|||||||
// See http://www.boost.org/libs/utility/assert.html for documentation.
|
// See http://www.boost.org/libs/utility/assert.html for documentation.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Stop inspect complaining about use of 'assert':
|
||||||
|
//
|
||||||
|
// boostinspect:naassert_macro
|
||||||
|
//
|
||||||
|
|
||||||
#undef BOOST_ASSERT
|
#undef BOOST_ASSERT
|
||||||
|
|
||||||
#if defined(BOOST_DISABLE_ASSERTS)
|
#if defined(BOOST_DISABLE_ASSERTS)
|
||||||
|
@@ -8,6 +8,8 @@
|
|||||||
// See http://www.boost.org/libs/utility/operators.htm for documentation.
|
// See http://www.boost.org/libs/utility/operators.htm for documentation.
|
||||||
|
|
||||||
// Revision History
|
// Revision History
|
||||||
|
// 16 Dec 10 Limit warning suppression for 4284 to older versions of VC++
|
||||||
|
// (Matthew Bradbury, fixes #4432)
|
||||||
// 07 Aug 08 Added "euclidean" spelling. (Daniel Frey)
|
// 07 Aug 08 Added "euclidean" spelling. (Daniel Frey)
|
||||||
// 03 Apr 08 Make sure "convertible to bool" is sufficient
|
// 03 Apr 08 Make sure "convertible to bool" is sufficient
|
||||||
// for T::operator<, etc. (Daniel Frey)
|
// for T::operator<, etc. (Daniel Frey)
|
||||||
@@ -88,7 +90,7 @@
|
|||||||
# pragma set woff 1234
|
# pragma set woff 1234
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(BOOST_MSVC)
|
#if BOOST_WORKAROUND(BOOST_MSVC, < 1600)
|
||||||
# pragma warning( disable : 4284 ) // complaint about return type of
|
# pragma warning( disable : 4284 ) // complaint about return type of
|
||||||
#endif // operator-> not begin a UDT
|
#endif // operator-> not begin a UDT
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
// See http://www.boost.org/lib/optional for documentation.
|
// See http://www.boost.org/libs/optional for documentation.
|
||||||
//
|
//
|
||||||
// You are welcome to contact the author at:
|
// You are welcome to contact the author at:
|
||||||
// fernando_cacciola@hotmail.com
|
// fernando_cacciola@hotmail.com
|
||||||
|
44
include/boost/utility/declval.hpp
Normal file
44
include/boost/utility/declval.hpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
// common_type.hpp ---------------------------------------------------------//
|
||||||
|
|
||||||
|
// Copyright 2010 Vicente J. Botet Escriba
|
||||||
|
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// See http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#ifndef BOOST_TYPE_TRAITS_EXT_DECLVAL__HPP
|
||||||
|
#define BOOST_TYPE_TRAITS_EXT_DECLVAL__HPP
|
||||||
|
|
||||||
|
#include <boost/config.hpp>
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
#include <boost/type_traits/add_rvalue_reference.hpp>
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------//
|
||||||
|
// //
|
||||||
|
// C++03 implementation of //
|
||||||
|
// Written by Vicente J. Botet Escriba //
|
||||||
|
//~ 20.3.4 Function template declval [declval]
|
||||||
|
//~ 1 The library provides the function template declval to simplify the definition of expressions which occur as
|
||||||
|
//~ unevaluated operands.
|
||||||
|
//~ 2 Remarks: If this function is used, the program is ill-formed.
|
||||||
|
//~ 3 Remarks: The template parameter T of declval may be an incomplete type.
|
||||||
|
//~ [ Example:
|
||||||
|
|
||||||
|
//~ template <class To, class From>
|
||||||
|
//~ decltype(static_cast<To>(declval<From>())) convert(From&&);
|
||||||
|
|
||||||
|
//~ declares a function template convert which only participats in overloading if the type From can be
|
||||||
|
//~ explicitly converted to type To. For another example see class template common_type (20.7.6.6). <20>end
|
||||||
|
//~ example ]
|
||||||
|
// //
|
||||||
|
//----------------------------------------------------------------------------//
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
typename add_rvalue_reference<T>::type declval(); //noexcept; // as unevaluated operand
|
||||||
|
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_TYPE_TRAITS_EXT_DECLVAL__HPP
|
@@ -5,7 +5,7 @@
|
|||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
// See http://www.boost.org/lib/optional for documentation.
|
// See http://www.boost.org/libs/optional for documentation.
|
||||||
//
|
//
|
||||||
// You are welcome to contact the author at:
|
// You are welcome to contact the author at:
|
||||||
// fernando_cacciola@hotmail.com
|
// fernando_cacciola@hotmail.com
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
// See http://www.boost.org/lib/optional for documentation.
|
// See http://www.boost.org/libs/optional for documentation.
|
||||||
//
|
//
|
||||||
// You are welcome to contact the author at:
|
// You are welcome to contact the author at:
|
||||||
// fernando_cacciola@hotmail.com
|
// fernando_cacciola@hotmail.com
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
// See http://www.boost.org/lib/optional for documentation.
|
// See http://www.boost.org/libs/optional for documentation.
|
||||||
//
|
//
|
||||||
// You are welcome to contact the author at:
|
// You are welcome to contact the author at:
|
||||||
// fernando_cacciola@hotmail.com
|
// fernando_cacciola@hotmail.com
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
//
|
//
|
||||||
// See http://www.boost.org/lib/optional for documentation.
|
// See http://www.boost.org/libs/optional for documentation.
|
||||||
//
|
//
|
||||||
// You are welcome to contact the author at:
|
// You are welcome to contact the author at:
|
||||||
// fernando_cacciola@hotmail.com
|
// fernando_cacciola@hotmail.com
|
||||||
|
10
index.html
10
index.html
@@ -14,20 +14,28 @@
|
|||||||
<p>But that doesn't mean there isn't useful stuff here. Take a look:</p>
|
<p>But that doesn't mean there isn't useful stuff here. Take a look:</p>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>
|
<p>
|
||||||
|
<a href="utility.htm#addressof">addressof</a><br>
|
||||||
<a href="assert.html">assert</a><br>
|
<a href="assert.html">assert</a><br>
|
||||||
<a href="base_from_member.html">base_from_member</a><br>
|
<a href="base_from_member.html">base_from_member</a><br>
|
||||||
|
<a href="utility.htm#BOOST_BINARY">BOOST_BINARY</a><br>
|
||||||
<a href="call_traits.htm">call_traits</a><br>
|
<a href="call_traits.htm">call_traits</a><br>
|
||||||
<a href="checked_delete.html">checked_delete</a><br>
|
<a href="checked_delete.html">checked_delete</a><br>
|
||||||
<a href="compressed_pair.htm">compressed_pair</a><br>
|
<a href="compressed_pair.htm">compressed_pair</a><br>
|
||||||
<a href="current_function.html">current_function</a><br>
|
<a href="current_function.html">current_function</a><br>
|
||||||
|
<a href="doc/html/declval.html">declval</a><br>
|
||||||
<a href="enable_if.html">enable_if</a><br>
|
<a href="enable_if.html">enable_if</a><br>
|
||||||
|
<a href="in_place_factories.html">in_place_factory</a><br>
|
||||||
<a href="iterator_adaptors.htm">iterator_adaptors</a><br>
|
<a href="iterator_adaptors.htm">iterator_adaptors</a><br>
|
||||||
<a href="generator_iterator.htm">generator iterator adaptors</a><br>
|
<a href="generator_iterator.htm">generator iterator adaptors</a><br>
|
||||||
|
<a href="utility.htm#functions_next_prior">next/prior</a><br>
|
||||||
|
<a href="utility.htm#Class_noncopyable">noncopyable</a><br>
|
||||||
<a href="operators.htm">operators</a><br>
|
<a href="operators.htm">operators</a><br>
|
||||||
|
<a href="utility.htm#result_of">result_of</a><br>
|
||||||
<a href="swap.html">swap</a><br>
|
<a href="swap.html">swap</a><br>
|
||||||
<a href="throw_exception.html">throw_exception</a><br>
|
<a href="throw_exception.html">throw_exception</a><br>
|
||||||
<a href="utility.htm">utility</a><br>
|
<a href="utility.htm">utility</a><br>
|
||||||
<a href="value_init.htm">value_init</a></p>
|
<a href="value_init.htm">value_init</a>
|
||||||
|
</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
<hr>
|
<hr>
|
||||||
<p>© Copyright Beman Dawes, 2001</p>
|
<p>© Copyright Beman Dawes, 2001</p>
|
||||||
|
@@ -32,6 +32,7 @@ test-suite utility
|
|||||||
[ compile result_of_test.cpp ]
|
[ compile result_of_test.cpp ]
|
||||||
[ run ../shared_iterator_test.cpp ]
|
[ run ../shared_iterator_test.cpp ]
|
||||||
[ run ../value_init_test.cpp ]
|
[ run ../value_init_test.cpp ]
|
||||||
|
[ run ../value_init_workaround_test.cpp ]
|
||||||
[ run ../initialized_test.cpp ]
|
[ run ../initialized_test.cpp ]
|
||||||
[ compile-fail ../value_init_test_fail1.cpp ]
|
[ compile-fail ../value_init_test_fail1.cpp ]
|
||||||
[ compile-fail ../value_init_test_fail2.cpp ]
|
[ compile-fail ../value_init_test_fail2.cpp ]
|
||||||
|
0
test/next_prior_test.cpp
Executable file → Normal file
0
test/next_prior_test.cpp
Executable file → Normal file
98
utility.htm
98
utility.htm
@@ -151,37 +151,95 @@ void f() {
|
|||||||
<code>result_of<F(T1, T2, ...,
|
<code>result_of<F(T1, T2, ...,
|
||||||
T<em>N</em>)>::type</code> defines the result type
|
T<em>N</em>)>::type</code> defines the result type
|
||||||
of the expression <code>f(t1, t2,
|
of the expression <code>f(t1, t2,
|
||||||
...,t<em>N</em>)</code>. The implementation permits
|
...,t<em>N</em>)</code>. This implementation permits
|
||||||
the type <code>F</code> to be a function pointer,
|
the type <code>F</code> to be a function pointer,
|
||||||
function reference, member function pointer, or class
|
function reference, member function pointer, or class
|
||||||
type.</p> <p>If your compiler does not support
|
type. By default, <em>N</em> may be any value between 0 and
|
||||||
<code>decltype</code>, then when <code>F</code> is a
|
10. To change the upper limit, define the macro
|
||||||
class type with a member type <code>result_type</code>,
|
<code>BOOST_RESULT_OF_NUM_ARGS</code> to the maximum
|
||||||
|
value for <em>N</em>. Class template <code>result_of</code>
|
||||||
|
resides in the header <code><<a
|
||||||
|
href="../../boost/utility/result_of.hpp">boost/utility/result_of.hpp</a>></code>.</p>
|
||||||
|
|
||||||
|
<p>If your compiler supports <code>decltype</code>,
|
||||||
|
then you can enable automatic result type deduction by
|
||||||
|
defining the macro <code>BOOST_RESULT_OF_USE_DECLTYPE</code>,
|
||||||
|
as in the following example.</p>
|
||||||
|
|
||||||
|
<blockquote>
|
||||||
|
<pre>#define BOOST_RESULT_OF_USE_DECLTYPE
|
||||||
|
#include <boost/utility/result_of.hpp>
|
||||||
|
|
||||||
|
struct functor {
|
||||||
|
template<class T>
|
||||||
|
T operator()(T x)
|
||||||
|
{
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef boost::result_of<
|
||||||
|
functor(int)
|
||||||
|
>::type type;</pre>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
|
<p>If <code>decltype</code> is not enabled,
|
||||||
|
then automatic result type deduction of function
|
||||||
|
objects is not possible. Instead, <code>result_of</code>
|
||||||
|
uses the following protocol to allow the programmer to
|
||||||
|
specify a type. When <code>F</code> is a class type with a
|
||||||
|
member type <code>result_type</code>,
|
||||||
<code>result_of<F(T1, T2, ...,
|
<code>result_of<F(T1, T2, ...,
|
||||||
T<em>N</em>)></code> is
|
T<em>N</em>)></code> is
|
||||||
<code>F::result_type</code>. When <code>F</code>
|
<code>F::result_type</code>. When <code>F</code> does
|
||||||
does not contain <code>result_type</code>,
|
not contain <code>result_type</code>,
|
||||||
<code>result_of<F(T1, T2, ...,
|
<code>result_of<F(T1, T2, ...,
|
||||||
T<em>N</em>)></code> is <code>F::result<F(T1,
|
T<em>N</em>)></code> is <code>F::result<F(T1,
|
||||||
T2, ..., T<em>N</em>)>::type</code> when
|
T2, ..., T<em>N</em>)>::type</code> when
|
||||||
<code><em>N</em> > 0</code> or <code>void</code>
|
<code><em>N</em> > 0</code> or <code>void</code>
|
||||||
when <code><em>N</em> = 0</code>. For additional
|
when <code><em>N</em> = 0</code>. Note that it is the
|
||||||
information about <code>result_of</code>, see the
|
responsibility of the programmer to ensure that
|
||||||
C++ Library Technical Report, <a
|
function objects accurately advertise their result
|
||||||
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">N1836</a>,
|
type via this protocol, as in the following
|
||||||
or, for motivation and design rationale, the <code>result_of</code> <a
|
example.</p>
|
||||||
href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1454.html">proposal</a>.</p>
|
|
||||||
|
|
||||||
<p>Class template <code>result_of</code> resides in
|
<blockquote>
|
||||||
the header <code><<a
|
<pre>struct functor {
|
||||||
href="../../boost/utility/result_of.hpp">boost/utility/result_of.hpp</a>></code>. By
|
template<class> struct result;
|
||||||
default, <em>N</em> may be any value between 0 and
|
|
||||||
10. To change the upper limit, define the macro
|
template<class F, class T>
|
||||||
<code>BOOST_RESULT_OF_NUM_ARGS</code> to the maximum
|
struct result<F(T)> {
|
||||||
value for <em>N</em>.</p>
|
typedef T type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
T operator()(T x)
|
||||||
|
{
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef boost::result_of<
|
||||||
|
functor(int)
|
||||||
|
>::type type;</pre>
|
||||||
|
</blockquote>
|
||||||
|
|
||||||
<a name="BOOST_NO_RESULT_OF"></a>
|
<a name="BOOST_NO_RESULT_OF"></a>
|
||||||
<p>This implementation of <code>result_of</code> requires class template partial specialization, the ability to parse function types properly, and support for SFINAE. If <code>result_of</code> is not supported by your compiler, including the header <code>boost/utility/result_of.hpp</code> will define the macro <code>BOOST_NO_RESULT_OF</code>. Contributed by Doug Gregor.</p>
|
<p>This implementation of <code>result_of</code>
|
||||||
|
requires class template partial specialization, the
|
||||||
|
ability to parse function types properly, and support
|
||||||
|
for SFINAE. If <code>result_of</code> is not supported
|
||||||
|
by your compiler, including the header
|
||||||
|
<code>boost/utility/result_of.hpp</code> will
|
||||||
|
define the macro <code>BOOST_NO_RESULT_OF</code>.</p>
|
||||||
|
|
||||||
|
<p>For additional information
|
||||||
|
about <code>result_of</code>, see the C++ Library
|
||||||
|
Technical Report,
|
||||||
|
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">N1836</a>,
|
||||||
|
or, for motivation and design rationale,
|
||||||
|
the <code>result_of</code> <a href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1454.html">proposal</a>.</p>
|
||||||
|
Contributed by Doug Gregor.</p>
|
||||||
|
|
||||||
<h2>Class templates for the Base-from-Member Idiom</h2>
|
<h2>Class templates for the Base-from-Member Idiom</h2>
|
||||||
<p>See <a href="base_from_member.html">separate documentation</a>.</p>
|
<p>See <a href="base_from_member.html">separate documentation</a>.</p>
|
||||||
|
144
value_init_workaround_test.cpp
Normal file
144
value_init_workaround_test.cpp
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
// Copyright 2010, Niels Dekker.
|
||||||
|
//
|
||||||
|
// 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)
|
||||||
|
//
|
||||||
|
// Test program for the boost::value_initialized<T> workaround.
|
||||||
|
//
|
||||||
|
// 17 June 2010 (Created) Niels Dekker
|
||||||
|
|
||||||
|
// Switch the workaround off, before inluding "value_init.hpp".
|
||||||
|
#define BOOST_DETAIL_VALUE_INIT_WORKAROUND 0
|
||||||
|
#include <boost/utility/value_init.hpp>
|
||||||
|
|
||||||
|
#include <iostream> // For cout.
|
||||||
|
#include <cstdlib> // For EXIT_SUCCESS and EXIT_FAILURE.
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
struct empty_struct
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
// A POD aggregate struct derived from an empty struct.
|
||||||
|
// Similar to struct Foo1 from Microsoft Visual C++ bug report 484295,
|
||||||
|
// "VC++ does not value-initialize members of derived classes without
|
||||||
|
// user-declared constructor", reported in 2009 by Sylvester Hesp:
|
||||||
|
// https://connect.microsoft.com/VisualStudio/feedback/details/484295
|
||||||
|
struct derived_struct: empty_struct
|
||||||
|
{
|
||||||
|
int data;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool is_value_initialized(const derived_struct& arg)
|
||||||
|
{
|
||||||
|
return arg.data == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class virtual_destructor_holder
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int i;
|
||||||
|
virtual ~virtual_destructor_holder()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
bool is_value_initialized(const virtual_destructor_holder& arg)
|
||||||
|
{
|
||||||
|
return arg.i == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Equivalent to the Stats class from GCC Bug 33916,
|
||||||
|
// "Default constructor fails to initialize array members", reported in 2007 by
|
||||||
|
// Michael Elizabeth Chastain: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33916
|
||||||
|
// and fixed for GCC 4.2.4.
|
||||||
|
class private_int_array_pair
|
||||||
|
{
|
||||||
|
friend bool is_value_initialized(const private_int_array_pair& arg);
|
||||||
|
private:
|
||||||
|
int first[12];
|
||||||
|
int second[12];
|
||||||
|
};
|
||||||
|
|
||||||
|
bool is_value_initialized(const private_int_array_pair& arg)
|
||||||
|
{
|
||||||
|
for ( unsigned i = 0; i < 12; ++i)
|
||||||
|
{
|
||||||
|
if ( (arg.first[i] != 0) || (arg.second[i] != 0) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool is_value_initialized(const T(& arg)[2])
|
||||||
|
{
|
||||||
|
return
|
||||||
|
is_value_initialized(arg[0]) &&
|
||||||
|
is_value_initialized(arg[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool is_value_initialized(const boost::value_initialized<T>& arg)
|
||||||
|
{
|
||||||
|
return is_value_initialized(arg.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns zero when the specified object is value-initializated, and one otherwise.
|
||||||
|
// Prints a message to standard output if the value-initialization has failed.
|
||||||
|
template <class T>
|
||||||
|
unsigned failed_to_value_initialized(const T& object, const char *const object_name)
|
||||||
|
{
|
||||||
|
if ( is_value_initialized(object) )
|
||||||
|
{
|
||||||
|
return 0u;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Note: Failed to value-initialize " << object_name << '.' << std::endl;
|
||||||
|
return 1u;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// A macro that passed both the name and the value of the specified object to
|
||||||
|
// the function above here.
|
||||||
|
#define FAILED_TO_VALUE_INITIALIZE(value) failed_to_value_initialized(value, #value)
|
||||||
|
|
||||||
|
// Equivalent to the dirty_stack() function from GCC Bug 33916,
|
||||||
|
// "Default constructor fails to initialize array members", reported in 2007 by
|
||||||
|
// Michael Elizabeth Chastain: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33916
|
||||||
|
void dirty_stack()
|
||||||
|
{
|
||||||
|
unsigned char array_on_stack[4096];
|
||||||
|
for (unsigned i = 0; i < sizeof(array_on_stack); ++i)
|
||||||
|
{
|
||||||
|
array_on_stack[i] = 0x11;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
dirty_stack();
|
||||||
|
|
||||||
|
// TODO More types may be added later.
|
||||||
|
const unsigned num_failures =
|
||||||
|
FAILED_TO_VALUE_INITIALIZE(boost::value_initialized<derived_struct>()) +
|
||||||
|
FAILED_TO_VALUE_INITIALIZE(boost::value_initialized<virtual_destructor_holder[2]>()) +
|
||||||
|
FAILED_TO_VALUE_INITIALIZE(boost::value_initialized<private_int_array_pair>());
|
||||||
|
|
||||||
|
#ifdef BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
|
||||||
|
// One or more failures are expected.
|
||||||
|
return num_failures > 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
|
#else
|
||||||
|
// No failures are expected.
|
||||||
|
return num_failures == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
|
#endif
|
||||||
|
}
|
Reference in New Issue
Block a user