diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 new file mode 100644 index 0000000..b12d71a --- /dev/null +++ b/doc/Jamfile.v2 @@ -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: + boost.root=../../../.. + + # Some general style settings: + table.footnote.number.format=1 + footnote.number.format=1 + + # HTML options first: + # Use graphics not text for navigation: + navig.graphics=1 + # PDF Options: + # TOC Generation: this is needed for FOP-0.9 and later: + fop1.extensions=0 + xep.extensions=1 + # TOC generation: this is needed for FOP 0.2, but must not be set to zero for FOP-0.9! + fop.extensions=0 + # No indent on body text: + body.start.indent=0pt + # Margin size: + page.margin.inner=0.5in + # Margin size: + page.margin.outer=0.5in + # Paper type = A4 + paper.type=A4 + # Yes, we want graphics for admonishments: + admon.graphics=1 + # Set this one for PDF generation *only*: + # default pnd graphics are awful in PDF form, + # better use SVG's instead: + pdf:admon.graphics.extension=".svg" + pdf:admon.graphics.path=$(boost-images)/ + pdf: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: + root.filename=declval + # How far down we chunk nested sections, basically all of them: + chunk.section.depth=0 + # Don't put the first section on the same page as the TOC: + chunk.first.sections=0 + # How far down sections get TOC's + toc.section.depth=1 + # Max depth in each TOC: + toc.max.depth=1 + # How far down we go with TOC's + generate.section.toc.level=1 + + ; + + + + + diff --git a/doc/declval.qbk b/doc/declval.qbk new file mode 100644 index 0000000..67e82d2 --- /dev/null +++ b/doc/declval.qbk @@ -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 + T&& declval(); // not used + +as part of the function template declaration + + template + decltype(static_cast(declval())) convert(From&&); + +or as part of a class template definition + + template class result_of; + + template + struct result_of + { + typedef decltype(declval()(declval()...)) 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()` 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 + typename std::add_rvalue_reference::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 ` + + namespace boost { + + template + typename add_rvalue_reference::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 add_rvalue_reference::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 + decltype(static_cast(declval())) convert(From&&); + +Declares a function template convert which only participats in overloading if the type From can be explicitly converted to type To. + +[endsect] + + + diff --git a/doc/html/declval.html b/doc/html/declval.html new file mode 100644 index 0000000..a2c5a01 --- /dev/null +++ b/doc/html/declval.html @@ -0,0 +1,163 @@ + + + +Declval + + + + + + + + + + + + +
Boost C++ LibrariesHomeLibrariesPeopleFAQMore
+
+
+
+
+
+

+Declval

+
+

+Howard Hinnant +

+

+Beman Dawes +

+

+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) +

+
+
+
+
+
+

Table of Contents

+
+
Overview
+
Reference
+
+
+
+ +

+ The motivation for declval + was introduced in 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. +

+
+
+ +

+ #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. +

+
+
+ + + +

Last revised: September 16, 2010 at 16:19:10 GMT

+
+
+ + diff --git a/include/boost/utility/declval.hpp b/include/boost/utility/declval.hpp new file mode 100644 index 0000000..41ec3dc --- /dev/null +++ b/include/boost/utility/declval.hpp @@ -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 + +//----------------------------------------------------------------------------// + +#include + +//----------------------------------------------------------------------------// +// // +// 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 +//~ decltype(static_cast(declval())) 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). —end +//~ example ] +// // +//----------------------------------------------------------------------------// + +namespace boost { + + template + typename add_rvalue_reference::type declval(); //noexcept; // as unevaluated operand + +} // namespace boost + +#endif // BOOST_TYPE_TRAITS_EXT_DECLVAL__HPP diff --git a/index.html b/index.html index 5af6f75..d957d79 100644 --- a/index.html +++ b/index.html @@ -20,6 +20,7 @@ checked_delete
compressed_pair
current_function
+ declval
enable_if
iterator_adaptors
generator iterator adaptors
@@ -40,3 +41,4 @@ 07 November, 2006

+