From 88f5ca0bfd4ef45df658ddda6011f41a6adf584f Mon Sep 17 00:00:00 2001 From: John Maddock Date: Fri, 17 Sep 2010 12:12:03 +0000 Subject: [PATCH 1/8] Add declval and common type from Vicente J. Botet Escriba. Regenerate docs. [SVN r65443] --- doc/declval.qbk | 104 ++++++++++++++++++++++++++++++ include/boost/utility/declval.hpp | 44 +++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 doc/declval.qbk create mode 100644 include/boost/utility/declval.hpp 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/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 From a04746196d8be414715d0abb6d64c2de6f2bfc87 Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Wed, 6 Apr 2011 20:21:51 +0000 Subject: [PATCH 2/8] Fix doc errors reported by Rob Stewart. Fixes #5421. [SVN r71047] --- doc/declval.qbk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/declval.qbk b/doc/declval.qbk index 67e82d2..8b59178 100644 --- a/doc/declval.qbk +++ b/doc/declval.qbk @@ -59,9 +59,9 @@ T is an lvalue-reference, otherwise an rvalue. To extend the domain of this func 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. +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 +The provision of a new library component that allows the production of values in unevaluated expressions is considered 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. @@ -96,7 +96,7 @@ The library provides the function template declval to simplify the definition of 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. +Declares a function template convert which only participates in overloading if the type From can be explicitly converted to type To. [endsect] From 8fd600df4774d8ccc0e9aa0f94b83582a3b0e417 Mon Sep 17 00:00:00 2001 From: "Vicente J. Botet Escriba" Date: Sun, 25 Mar 2012 15:58:40 +0000 Subject: [PATCH 3/8] Utility: Apply patch for 6570: Adding noexcept to boost::declval [SVN r77539] --- include/boost/utility/declval.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/boost/utility/declval.hpp b/include/boost/utility/declval.hpp index 41ec3dc..123f776 100644 --- a/include/boost/utility/declval.hpp +++ b/include/boost/utility/declval.hpp @@ -13,6 +13,7 @@ //----------------------------------------------------------------------------// #include +#include //----------------------------------------------------------------------------// // // @@ -36,9 +37,13 @@ namespace boost { +#if !defined(BOOST_NO_RVALUE_REFERENCES) template typename add_rvalue_reference::type declval(); //noexcept; // as unevaluated operand - +#else + template + typename add_lvalue_reference::type declval() BOOST_NOEXCEPT; // as unevaluated operand +#endif } // namespace boost #endif // BOOST_TYPE_TRAITS_EXT_DECLVAL__HPP From d6fd3f6ccbe6839eef2c8c71c9accbbf1a8671ee Mon Sep 17 00:00:00 2001 From: "Vicente J. Botet Escriba" Date: Sun, 25 Mar 2012 18:28:24 +0000 Subject: [PATCH 4/8] Utility: Added doc for Adding noexcept to boost::declval [SVN r77543] --- doc/declval.qbk | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/doc/declval.qbk b/doc/declval.qbk index 8b59178..9774422 100644 --- a/doc/declval.qbk +++ b/doc/declval.qbk @@ -1,7 +1,6 @@ [/ / Copyright (c) 2008 Howard Hinnant - / Copyright (c) 2008 Beman Dawes - / Copyright (c) 2009-20010 Vicente J. Botet Escriba + / Copyright (c) 2009-20012 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) @@ -10,11 +9,9 @@ [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] + [copyright 2009-2012 Vicente J. Botet Escriba] [license Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -77,7 +74,7 @@ This extremely light-weight function is expected to be part of the daily tool-bo namespace boost { template - typename add_rvalue_reference::type declval(); //noexcept; // as unevaluated operand + typename add_rvalue_reference::type declval() noexcept; // as unevaluated operand } // namespace boost @@ -100,5 +97,19 @@ Declares a function template convert which only participates in overloading if t [endsect] +[/===============] +[section History] +[/===============] + +[heading boost 1.50] + +New Features: + +* [@http://svn.boost.org/trac/boost/ticket/6570 #6570] Adding noexcept to boost::declval. + + +[endsect] + + From 590d24cb2ee21b986d7d1abcab4d660c88c2cfb2 Mon Sep 17 00:00:00 2001 From: "Vicente J. Botet Escriba" Date: Sun, 25 Mar 2012 23:17:39 +0000 Subject: [PATCH 5/8] Utility: Fix for Adding noexcept to boost::declval [SVN r77552] --- include/boost/utility/declval.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/utility/declval.hpp b/include/boost/utility/declval.hpp index 123f776..54b3158 100644 --- a/include/boost/utility/declval.hpp +++ b/include/boost/utility/declval.hpp @@ -39,7 +39,7 @@ namespace boost { #if !defined(BOOST_NO_RVALUE_REFERENCES) template - typename add_rvalue_reference::type declval(); //noexcept; // as unevaluated operand + typename add_rvalue_reference::type declval() BOOST_NOEXCEPT; // as unevaluated operand #else template typename add_lvalue_reference::type declval() BOOST_NOEXCEPT; // as unevaluated operand From 00e3a56d57a10c633bb1182bcacde56529fa0372 Mon Sep 17 00:00:00 2001 From: "Vicente J. Botet Escriba" Date: Mon, 26 Mar 2012 17:07:17 +0000 Subject: [PATCH 6/8] Utility: Rollback unwanted commit while adding noexcept to boost::declval [SVN r77562] --- include/boost/utility/declval.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/boost/utility/declval.hpp b/include/boost/utility/declval.hpp index 54b3158..2924cd7 100644 --- a/include/boost/utility/declval.hpp +++ b/include/boost/utility/declval.hpp @@ -37,13 +37,13 @@ namespace boost { -#if !defined(BOOST_NO_RVALUE_REFERENCES) +//#if !defined(BOOST_NO_RVALUE_REFERENCES) template typename add_rvalue_reference::type declval() BOOST_NOEXCEPT; // as unevaluated operand -#else - template - typename add_lvalue_reference::type declval() BOOST_NOEXCEPT; // as unevaluated operand -#endif +//#else +// template +// typename add_lvalue_reference::type declval() BOOST_NOEXCEPT; // as unevaluated operand +//#endif } // namespace boost #endif // BOOST_TYPE_TRAITS_EXT_DECLVAL__HPP From 9dca8381fe081dfaaa981e1c07fea826d18bf96f Mon Sep 17 00:00:00 2001 From: "Vicente J. Botet Escriba" Date: Mon, 28 May 2012 18:44:24 +0000 Subject: [PATCH 7/8] Utility/declval: update history. [SVN r78729] --- doc/declval.qbk | 2 +- include/boost/utility/declval.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/declval.qbk b/doc/declval.qbk index 9774422..7bf5cb5 100644 --- a/doc/declval.qbk +++ b/doc/declval.qbk @@ -103,7 +103,7 @@ Declares a function template convert which only participates in overloading if t [heading boost 1.50] -New Features: +Fixes: * [@http://svn.boost.org/trac/boost/ticket/6570 #6570] Adding noexcept to boost::declval. diff --git a/include/boost/utility/declval.hpp b/include/boost/utility/declval.hpp index 2924cd7..d74610c 100644 --- a/include/boost/utility/declval.hpp +++ b/include/boost/utility/declval.hpp @@ -13,7 +13,7 @@ //----------------------------------------------------------------------------// #include -#include +//#include //----------------------------------------------------------------------------// // // From 8ced326b7004001ed7d4baea8aad295a793cad54 Mon Sep 17 00:00:00 2001 From: Michel Morin Date: Tue, 30 Oct 2012 16:51:16 +0000 Subject: [PATCH 8/8] Tweak comments (removing a non-ascii character, updating references to the C++11 standard, etc.) and rename the include guard macro. [SVN r81112] --- include/boost/utility/declval.hpp | 41 ++++++++++++++----------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/include/boost/utility/declval.hpp b/include/boost/utility/declval.hpp index d74610c..a4ab2c8 100644 --- a/include/boost/utility/declval.hpp +++ b/include/boost/utility/declval.hpp @@ -1,49 +1,44 @@ -// common_type.hpp ---------------------------------------------------------// +// declval.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 +#ifndef BOOST_UTILITY_DECLVAL_HPP +#define BOOST_UTILITY_DECLVAL_HPP #include //----------------------------------------------------------------------------// #include -//#include //----------------------------------------------------------------------------// // // // C++03 implementation of // +// 20.2.4 Function template declval [declval] // // 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 ] // // +// 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 participates in overloading +// if the type From can be explicitly converted to type To. For another example +// see class template common_type (20.9.7.6). -end example ] //----------------------------------------------------------------------------// namespace boost { -//#if !defined(BOOST_NO_RVALUE_REFERENCES) template typename add_rvalue_reference::type declval() BOOST_NOEXCEPT; // as unevaluated operand -//#else -// template -// typename add_lvalue_reference::type declval() BOOST_NOEXCEPT; // as unevaluated operand -//#endif + } // namespace boost -#endif // BOOST_TYPE_TRAITS_EXT_DECLVAL__HPP +#endif // BOOST_UTILITY_DECLVAL_HPP