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/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


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 + diff --git a/utility.htm b/utility.htm index 3ac5d42..474a338 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 < +

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

+

This implementation of result_of requires class template partial specialization, the