From 95d2c38379cc6add757ef75a53dfe7d71dbfbf02 Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Wed, 6 Apr 2011 20:21:51 +0000 Subject: [PATCH 1/8] Fix doc errors reported by Rob Stewart. Fixes #5421. [SVN r71047] --- doc/declval.qbk | 6 +++--- doc/html/declval.html | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 17 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] diff --git a/doc/html/declval.html b/doc/html/declval.html index a2c5a01..2810dc4 100644 --- a/doc/html/declval.html +++ b/doc/html/declval.html @@ -3,7 +3,7 @@ Declval - + @@ -17,7 +17,7 @@
-
+

@@ -35,9 +35,9 @@

-
+
-

+

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)

@@ -49,10 +49,10 @@

Table of Contents

Overview
-
Reference
+
Reference
-
+
@@ -103,18 +103,18 @@ 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 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. + 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.

-
+

#include <boost/utility/declval.hpp> @@ -148,13 +148,13 @@ decltype(static_cast<To>(declval<From>())) convert(From&&);

- Declares a function template convert which only participats in overloading + Declares a function template convert which only participates in overloading if the type From can be explicitly converted to type To.

- +

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

Last revised: April 06, 2011 at 20:06:10 GMT


From 5684a2f2b3b43f297eee59e90a0f0621c0a4bb0e Mon Sep 17 00:00:00 2001 From: Jeremiah Willcock Date: Wed, 13 Apr 2011 02:30:39 +0000 Subject: [PATCH 2/8] Applied doc patches from Matt Calabrese [SVN r71221] --- enable_if.html | 111 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 93 insertions(+), 18 deletions(-) diff --git a/enable_if.html b/enable_if.html index a17a290..8ea33bb 100644 --- a/enable_if.html +++ b/enable_if.html @@ -21,6 +21,7 @@

Copyright 2003 Jaakko Järvi, Jeremiah Willcock, Andrew Lumsdaine.
+Copyright 2011 Matt Calabrese.

@@ -81,7 +82,7 @@ definitions to find this out. Instantiating the latter definition with
int::result_type negate(const int&);
 
 
-where the return type is invalid. If this was an error, adding an unrelated function template +where the return type is invalid. If this were an error, adding an unrelated function template (that was never called) could break otherwise valid code. Due to the SFINAE principle the above example is not, however, erroneous. The latter definition of negate is simply removed from the overload resolution set.
@@ -154,6 +155,7 @@ typename enable_if<boost::is_arithmetic<T>, T>::type foo(T t) { return t; } +

3  Using enable_if

@@ -162,8 +164,19 @@ foo(T t) { return t; } The enable_if templates are defined in boost/utility/enable_if.hpp, which is included by boost/utility.hpp.

-The enable_if template can be used either as the return type, or as an -extra argument. For example, the foo function in the previous section could also be written +With respect to function templates, enable_if can be used in multiple different ways: + +
    +
  • As the return type of an instantiatied function +
  • As an extra parameter of an instantiated function +
  • As an extra template parameter (useful only in a compiler that supports C++0x default +arguments for function template parameters, see Enabling function +templates in C++0x for details) +
+ +In the previous section, the return type form of enable_if was shown. As an example +of using the form of enable_if that works via an extra function parameter, the +foo function in the previous section could also be written as:
template <class T>
 T foo(T t, typename enable_if<boost::is_arithmetic<T> >::type* dummy = 0); 
@@ -173,18 +186,80 @@ a default value to keep the parameter hidden from client code.
 Note that the second template argument was not given to enable_if, as the default 
 void gives the desired behavior.

-Whether to write the enabler as an argument or within the return type is -largely a matter of taste, but for certain functions, only one -alternative is possible: +Which way to write the enabler is largely a matter of taste, but for certain functions, only a +subset of the options is possible:
  • -Operators have a fixed number of arguments, thus enable_if must be used in the return type. -
  • Constructors and destructors do not have a return type; an extra argument is the only option. -
  • There does not seem to be a way to specify an enabler for a conversion operator. Converting constructors, -however, can have enablers as extra default arguments. +Many operators have a fixed number of arguments, thus enable_if must be used either in the +return type or in an extra template parameter. +
  • Functions that have a variadic parameter list must use either the return type form or an extra +template parameter. +
  • Constructors do not have a return type so you must use either an extra function parameter or an +extra template parameter. +
  • Constructors that have a variadic parameter list must an extra template parameter. +
  • Conversion operators can only be written with an extra template parameter.
+ + + +

3.1  Enabling function templates in C++0x

+ +In a compiler which supports C++0x default arguments for function template parameters, you can +enable and disable function templates by adding an additional template parameter. This approach +works in all situations where you would use either the return type form of enable_if or +the function parameter form, including operators, constructors, variadic function templates, and +even overloaded conversion operations. + +As an example: + +
#include <boost/type_traits/is_arithmetic.hpp>
+#include <boost/type_traits/is_pointer.hpp>
+#include <boost/utility/enable_if.hpp>
+
+class test
+{
+public:
+  // A constructor that works for any argument list of size 10
+  template< class... T
+          , typename boost::enable_if_c< sizeof...( T ) == 10, int >::type = 0
+          >
+  test( T&&... );
+
+  // A conversion operation that can convert to any arithmetic type
+  template< class T
+          , typename boost::enable_if< boost::is_arithmetic< T >, int >::type = 0
+          >
+  operator T() const;
+
+  // A conversion operation that can convert to any pointer type
+  template< class T
+          , typename boost::enable_if< boost::is_pointer< T >, int >::type = 0
+          >
+  operator T() const;
+};
+
+int main()
+{
+  // Works
+  test test_( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
+
+  // Fails as expected
+  test fail_construction( 1, 2, 3, 4, 5 );
+
+  // Works by calling the conversion operator enabled for arithmetic types
+  int arithmetic_object = test_;
+
+  // Works by calling the conversion operator enabled for pointer types
+  int* pointer_object = test_;
+
+  // Fails as expected
+  struct {} fail_conversion = test_;
+}
+
+
+ -

3.1  Enabling template class specializations

+

3.2  Enabling template class specializations

Class template specializations can be enabled or disabled with enable_if. @@ -210,7 +285,7 @@ is the correct value.

-

3.2  Overlapping enabler conditions

+

3.3  Overlapping enabler conditions

Once the compiler has examined the enabling conditions and included the @@ -239,7 +314,7 @@ partial specializations as well.

-

3.3  Lazy enable_if

+

3.4  Lazy enable_if

In some cases it is necessary to avoid instantiating part of a @@ -285,7 +360,7 @@ above example, is_multipliable<T, U>::value defines when
-

3.4  Compiler workarounds

+

3.5  Compiler workarounds

Some compilers flag functions as ambiguous if the only distinguishing factor is a different @@ -367,9 +442,9 @@ David Vandevoorde and Nicolai M. Josuttis. Addison-Wesley, 2002.
-

Copyright Jaakko Järvi, Jeremiah Willcock and Andrew Lumsdaine
-{jajarvi|jewillco|lums}@osl.iu.edu
-Indiana University
+

Copyright Jaakko Järvi*, Jeremiah Willcock*, Andrew Lumsdaine*, Matt Calabrese
+{jajarvi|jewillco|lums}@osl.iu.edu, rivorus@gmail.com
+*Indiana University
Open Systems Lab
Use, modification and distribution are subject to the Boost Software License, Version 1.0. @@ -386,4 +461,4 @@ or copy at HEVEA. - \ No newline at end of file + From 1d146d010a72040eafedba6c4f97954cb7ba2371 Mon Sep 17 00:00:00 2001 From: Daniel Walker Date: Fri, 6 May 2011 19:55:35 +0000 Subject: [PATCH 3/8] upped BOOST_RESULT_OF_NUM_ARGS for Phoenix [SVN r71769] --- include/boost/utility/result_of.hpp | 2 +- utility.htm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/utility/result_of.hpp b/include/boost/utility/result_of.hpp index 41cc176..77c26fe 100644 --- a/include/boost/utility/result_of.hpp +++ b/include/boost/utility/result_of.hpp @@ -27,7 +27,7 @@ #include #ifndef BOOST_RESULT_OF_NUM_ARGS -# define BOOST_RESULT_OF_NUM_ARGS 10 +# define BOOST_RESULT_OF_NUM_ARGS 16 #endif namespace boost { diff --git a/utility.htm b/utility.htm index 3ac5d42..b9707db 100644 --- a/utility.htm +++ b/utility.htm @@ -155,7 +155,7 @@ void f() { the type F to be a function pointer, function reference, member function pointer, or class type. By default, N may be any value between 0 and - 10. To change the upper limit, define the macro + 16. To change the upper limit, define the macro BOOST_RESULT_OF_NUM_ARGS to the maximum value for N. Class template result_of resides in the header < Date: Wed, 1 Jun 2011 19:29:57 +0000 Subject: [PATCH 4/8] updated result_of doc with decltype info [SVN r72336] --- utility.htm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/utility.htm b/utility.htm index b9707db..bca0e52 100644 --- a/utility.htm +++ b/utility.htm @@ -224,6 +224,15 @@ typedef boost::result_of< >::type type;

+

In a future + release, BOOST_RESULT_OF_USE_DECLTYPE + may be enabled by default on compilers that + support decltype, so if you use the above + protocol please take care to ensure that + the result_type + and result<> members are + accurate.

+

This implementation of result_of requires class template partial specialization, the From 6d196c4244b69a09e10f586e19418275dddb1550 Mon Sep 17 00:00:00 2001 From: Daniel Walker Date: Wed, 1 Jun 2011 20:02:40 +0000 Subject: [PATCH 5/8] added tr1_result_of info to result_of doc [SVN r72337] --- utility.htm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/utility.htm b/utility.htm index bca0e52..5108060 100644 --- a/utility.htm +++ b/utility.htm @@ -231,7 +231,11 @@ typedef boost::result_of< protocol please take care to ensure that the result_type and result<> members are - accurate.

+ accurate. If you wish to continue to use the protocol + on compilers that support decltype, + use boost::tr1_result_of, which is + also defined + in <boost/utility/result_of.hpp>.

This implementation of result_of From 9525d062b36ab11b5bee4d684810cba7f06ce1e3 Mon Sep 17 00:00:00 2001 From: Daniel Walker Date: Fri, 3 Jun 2011 14:45:59 +0000 Subject: [PATCH 6/8] added clarification to result_of doc [SVN r72377] --- utility.htm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/utility.htm b/utility.htm index 5108060..474a338 100644 --- a/utility.htm +++ b/utility.htm @@ -230,11 +230,12 @@ typedef boost::result_of< support decltype, so if you use the above protocol please take care to ensure that the result_type - and result<> members are - accurate. If you wish to continue to use the protocol - on compilers that support decltype, - use boost::tr1_result_of, which is - also defined + and result<> members accurately + represent the result type. If you wish to continue to + use the protocol on compilers that + support decltype, + use boost::tr1_result_of, which is also + defined in <boost/utility/result_of.hpp>.

From 26b39384e36c2ce4cf8232f66d9fe0677fbb03c3 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Tue, 14 Jun 2011 08:27:14 +0000 Subject: [PATCH 7/8] Apply patch from #5607. Refs #5607. [SVN r72580] --- include/boost/current_function.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/boost/current_function.hpp b/include/boost/current_function.hpp index aa5756e..cb36e35 100644 --- a/include/boost/current_function.hpp +++ b/include/boost/current_function.hpp @@ -28,7 +28,7 @@ namespace detail inline void current_function_helper() { -#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) +#if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) || defined(__ghs__) # define BOOST_CURRENT_FUNCTION __PRETTY_FUNCTION__ @@ -65,3 +65,4 @@ inline void current_function_helper() } // namespace boost #endif // #ifndef BOOST_CURRENT_FUNCTION_HPP_INCLUDED + From fe653d0a9ae5f27fb8eca77d944aa44a5cc637b0 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Sat, 20 Aug 2011 16:03:58 +0000 Subject: [PATCH 8/8] Change call_traits to pass enum's by value. Fixes #5790. [SVN r73953] --- call_traits_test.cpp | 8 +++++++- include/boost/detail/call_traits.hpp | 20 ++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/call_traits_test.cpp b/call_traits_test.cpp index 72852c4..9e49b68 100644 --- a/call_traits_test.cpp +++ b/call_traits_test.cpp @@ -210,8 +210,10 @@ int main() comparible_UDT u; c1(u); call_traits_checker c2; + call_traits_checker c2b; int i = 2; c2(i); + c2b(one); int* pi = &i; int a[2] = {1,2}; #if defined(BOOST_MSVC6_MEMBER_TEMPLATES) && !defined(__ICL) @@ -292,7 +294,11 @@ int main() BOOST_CHECK_TYPE(incomplete_type&, boost::call_traits::reference); BOOST_CHECK_TYPE(const incomplete_type&, boost::call_traits::const_reference); BOOST_CHECK_TYPE(const incomplete_type&, boost::call_traits::param_type); - + // test enum: + BOOST_CHECK_TYPE(enum_UDT, boost::call_traits::value_type); + BOOST_CHECK_TYPE(enum_UDT&, boost::call_traits::reference); + BOOST_CHECK_TYPE(const enum_UDT&, boost::call_traits::const_reference); + BOOST_CHECK_TYPE(const enum_UDT, boost::call_traits::param_type); return 0; } diff --git a/include/boost/detail/call_traits.hpp b/include/boost/detail/call_traits.hpp index 6ad646e..36dea00 100644 --- a/include/boost/detail/call_traits.hpp +++ b/include/boost/detail/call_traits.hpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -43,20 +44,26 @@ struct ct_imp2 typedef const T param_type; }; -template +template struct ct_imp { typedef const T& param_type; }; -template -struct ct_imp +template +struct ct_imp { typedef typename ct_imp2::param_type param_type; }; -template -struct ct_imp +template +struct ct_imp +{ + typedef typename ct_imp2::param_type param_type; +}; + +template +struct ct_imp { typedef const T param_type; }; @@ -79,7 +86,8 @@ public: typedef typename boost::detail::ct_imp< T, ::boost::is_pointer::value, - ::boost::is_arithmetic::value + ::boost::is_arithmetic::value, + ::boost::is_enum::value >::param_type param_type; };