From ff0cb364168707e47378fe87d68586131f957e8f Mon Sep 17 00:00:00 2001
From: Daniel Walker
Date: Sat, 1 Sep 2012 20:00:33 +0000
Subject: [PATCH] Fixes [6754]. Minor edits to documentation.
[SVN r80352]
---
test/result_of_test.cpp | 106 ++++++++++++++++++++++------------------
utility.htm | 34 ++++++-------
2 files changed, 76 insertions(+), 64 deletions(-)
diff --git a/test/result_of_test.cpp b/test/result_of_test.cpp
index c006d35..3f6da9e 100644
--- a/test/result_of_test.cpp
+++ b/test/result_of_test.cpp
@@ -7,10 +7,6 @@
#include
-#ifndef BOOST_NO_DECLTYPE
-# define BOOST_RESULT_OF_USE_DECLTYPE
-#endif
-
// For more information, see http://www.boost.org/libs/utility
#include
#include
@@ -66,6 +62,9 @@ struct int_result_type_and_float_result_of_and_char_return_template
char operator()(char);
};
+template
+struct cv_overload_check {};
+
struct result_of_member_function_template
{
template struct result;
@@ -73,13 +72,13 @@ struct result_of_member_function_template
template struct result { typedef That type; };
template typename result::type operator()(T);
- template struct result { typedef const That type; };
+ template struct result { typedef cv_overload_check type; };
template typename result::type operator()(T) const;
- template struct result { typedef volatile That type; };
+ template struct result { typedef cv_overload_check type; };
template typename result::type operator()(T) volatile;
- template struct result { typedef const volatile That type; };
+ template struct result { typedef cv_overload_check type; };
template typename result::type operator()(T) const volatile;
template struct result { typedef That & type; };
@@ -95,13 +94,16 @@ struct result_of_member_function_template
template typename result::type operator()(T const volatile &, T);
};
-struct no_result_type_or_result_of
+struct no_result_type_or_result
{
- int operator()(double);
- short operator()(double) const;
- unsigned int operator()();
- unsigned short operator()() volatile;
- const unsigned short operator()() const volatile;
+ short operator()(double);
+ cv_overload_check operator()(double) const;
+ cv_overload_check operator()(double) volatile;
+ cv_overload_check operator()(double) const volatile;
+ int operator()();
+ cv_overload_check operator()() const;
+ cv_overload_check operator()() volatile;
+ cv_overload_check operator()() const volatile;
#if !defined(BOOST_NO_RVALUE_REFERENCES)
short operator()(int&&);
int operator()(int&);
@@ -110,13 +112,16 @@ struct no_result_type_or_result_of
};
template
-struct no_result_type_or_result_of_template
+struct no_result_type_or_result_template
{
- int operator()(double);
- short operator()(double) const;
- unsigned int operator()();
- unsigned short operator()() volatile;
- const unsigned short operator()() const volatile;
+ short operator()(double);
+ cv_overload_check operator()(double) const;
+ cv_overload_check operator()(double) volatile;
+ cv_overload_check operator()(double) const volatile;
+ int operator()();
+ cv_overload_check operator()() const;
+ cv_overload_check operator()() volatile;
+ cv_overload_check operator()() const volatile;
#if !defined(BOOST_NO_RVALUE_REFERENCES)
short operator()(int&&);
int operator()(int&);
@@ -161,7 +166,7 @@ int main()
// Prior to decltype, result_of could not deduce the return type
// nullary function objects unless they exposed a result_type.
-#if !defined(BOOST_NO_DECLTYPE)
+#if defined(BOOST_RESULT_OF_USE_DECLTYPE)
BOOST_STATIC_ASSERT((is_same::type, int>::value));
BOOST_STATIC_ASSERT((is_same::type, int>::value));
BOOST_STATIC_ASSERT((is_same(void)>::type, int>::value));
@@ -173,14 +178,11 @@ int main()
BOOST_STATIC_ASSERT((is_same(void)>::type, void>::value));
#endif
- BOOST_STATIC_ASSERT((is_same::type, int>::value));
- BOOST_STATIC_ASSERT((is_same(char)>::type, int>::value));
-
// Prior to decltype, result_of ignored a nested result<> if
// result_type was defined. After decltype, result_of deduces the
// actual return type of the function object, ignoring both
// result<> and result_type.
-#if !defined(BOOST_NO_DECLTYPE)
+#if defined(BOOST_RESULT_OF_USE_DECLTYPE)
BOOST_STATIC_ASSERT((is_same::type, char>::value));
BOOST_STATIC_ASSERT((is_same(char)>::type, char>::value));
#else
@@ -188,6 +190,9 @@ int main()
BOOST_STATIC_ASSERT((is_same(char)>::type, int>::value));
#endif
+ BOOST_STATIC_ASSERT((is_same::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same(char)>::type, int>::value));
+
BOOST_STATIC_ASSERT((is_same::type, int>::value));
BOOST_STATIC_ASSERT((is_same::type, int>::value));
BOOST_STATIC_ASSERT((is_same::type, int>::value));
@@ -211,18 +216,18 @@ int main()
BOOST_STATIC_ASSERT((is_same::type, int>::value));
BOOST_STATIC_ASSERT((is_same::type, double>::value));
- BOOST_STATIC_ASSERT((is_same::type, const double>::value));
- BOOST_STATIC_ASSERT((is_same::type, volatile double>::value));
- BOOST_STATIC_ASSERT((is_same::type, const volatile double>::value));
+ BOOST_STATIC_ASSERT((is_same::type, cv_overload_check >::value));
+ BOOST_STATIC_ASSERT((is_same::type, cv_overload_check >::value));
+ BOOST_STATIC_ASSERT((is_same::type, cv_overload_check >::value));
BOOST_STATIC_ASSERT((is_same::type, int &>::value));
BOOST_STATIC_ASSERT((is_same::type, int const &>::value));
BOOST_STATIC_ASSERT((is_same::type, int volatile &>::value));
BOOST_STATIC_ASSERT((is_same::type, int const volatile &>::value));
BOOST_STATIC_ASSERT((is_same::type, double>::value));
- BOOST_STATIC_ASSERT((is_same::type, const double>::value));
- BOOST_STATIC_ASSERT((is_same::type, volatile double>::value));
- BOOST_STATIC_ASSERT((is_same::type, const volatile double>::value));
+ BOOST_STATIC_ASSERT((is_same::type, cv_overload_check >::value));
+ BOOST_STATIC_ASSERT((is_same::type, cv_overload_check >::value));
+ BOOST_STATIC_ASSERT((is_same::type, cv_overload_check >::value));
BOOST_STATIC_ASSERT((is_same::type, int &>::value));
BOOST_STATIC_ASSERT((is_same::type, int const &>::value));
BOOST_STATIC_ASSERT((is_same::type, int volatile &>::value));
@@ -235,24 +240,31 @@ int main()
BOOST_STATIC_ASSERT((is_same::type, int>::value));
BOOST_STATIC_ASSERT((is_same::type,int>::value));
-#if !defined(BOOST_NO_DECLTYPE)
- BOOST_STATIC_ASSERT((is_same::type, int>::value));
- BOOST_STATIC_ASSERT((is_same::type, unsigned int>::value));
- BOOST_STATIC_ASSERT((is_same::type, short>::value));
- BOOST_STATIC_ASSERT((is_same::type, unsigned short>::value));
- BOOST_STATIC_ASSERT((is_same::type, const unsigned short>::value));
- BOOST_STATIC_ASSERT((is_same(double)>::type, int>::value));
- BOOST_STATIC_ASSERT((is_same(void)>::type, unsigned int>::value));
- BOOST_STATIC_ASSERT((is_same(double)>::type, short>::value));
- BOOST_STATIC_ASSERT((is_same(void)>::type, unsigned short>::value));
- BOOST_STATIC_ASSERT((is_same(void)>::type, const unsigned short>::value));
+#if defined(BOOST_RESULT_OF_USE_DECLTYPE)
+ BOOST_STATIC_ASSERT((is_same::type, short>::value));
+ BOOST_STATIC_ASSERT((is_same::type, cv_overload_check >::value));
+ BOOST_STATIC_ASSERT((is_same::type, cv_overload_check >::value));
+ BOOST_STATIC_ASSERT((is_same::type, cv_overload_check >::value));
+ BOOST_STATIC_ASSERT((is_same::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same::type, cv_overload_check >::value));
+ BOOST_STATIC_ASSERT((is_same::type, cv_overload_check >::value));
+ BOOST_STATIC_ASSERT((is_same::type, cv_overload_check >::value));
+
+ BOOST_STATIC_ASSERT((is_same(double)>::type, short>::value));
+ BOOST_STATIC_ASSERT((is_same(double)>::type, cv_overload_check >::value));
+ BOOST_STATIC_ASSERT((is_same(double)>::type, cv_overload_check >::value));
+ BOOST_STATIC_ASSERT((is_same(double)>::type, cv_overload_check >::value));
+ BOOST_STATIC_ASSERT((is_same(void)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same(void)>::type, cv_overload_check >::value));
+ BOOST_STATIC_ASSERT((is_same(void)>::type, cv_overload_check >::value));
+ BOOST_STATIC_ASSERT((is_same(void)>::type, cv_overload_check >::value));
#if !defined(BOOST_NO_RVALUE_REFERENCES)
- BOOST_STATIC_ASSERT((is_same::type, short>::value));
- BOOST_STATIC_ASSERT((is_same::type, int>::value));
- BOOST_STATIC_ASSERT((is_same::type, long>::value));
- BOOST_STATIC_ASSERT((is_same(int&&)>::type, short>::value));
- BOOST_STATIC_ASSERT((is_same(int&)>::type, int>::value));
- BOOST_STATIC_ASSERT((is_same(int const&)>::type, long>::value));
+ BOOST_STATIC_ASSERT((is_same::type, short>::value));
+ BOOST_STATIC_ASSERT((is_same::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same::type, long>::value));
+ BOOST_STATIC_ASSERT((is_same(int&&)>::type, short>::value));
+ BOOST_STATIC_ASSERT((is_same(int&)>::type, int>::value));
+ BOOST_STATIC_ASSERT((is_same(int const&)>::type, long>::value));
#endif
#endif
diff --git a/utility.htm b/utility.htm
index 65ead22..73bd692 100644
--- a/utility.htm
+++ b/utility.htm
@@ -163,7 +163,7 @@ void f() {
If your compiler's support for decltype
is
adequate, result_of
automatically uses it to
- deduce the result type of your callable.
+ deduce the result type of your callable object.
#include <boost/utility/result_of.hpp>
@@ -182,7 +182,7 @@ typedef boost::result_of<
You can test whether result_of
is using
- decltype
checking if the macro
+ decltype
by checking if the macro
BOOST_RESULT_OF_USE_DECLTYPE
is defined after
including result_of.hpp
. You can also force
result_of
to use decltype
by
@@ -230,27 +230,27 @@ typedef boost::result_of<
>::type type; // type is int
-
If you are writing a reusable function object
- that should work with result_of
, for
+
Since decltype
is a new language
+ feature recently standardized in C++11,
+ if you are writing a function object
+ to be used with result_of
, for
maximum portability, you might consider following
the above protocol even if your compiler has
- proper decltype
support. If you do,
- take care to ensure that the
+ proper decltype
support. If you wish to continue to
+ use the protocol on compilers that
+ support decltype
, there are two options:
+ You can use boost::tr1_result_of
, which is also
+ defined in <boost/utility/result_of.hpp>
.
+ Alternatively, you can define the macro
+ BOOST_RESULT_OF_USE_TR1
, which causes
+ result_of
to use the protocol described
+ above instead of decltype
. If you choose to
+ follow the protocol, take care to ensure that the
result_type
and
result<>
members accurately
represent the return type of
operator()
.
- 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>
. You can also define the macro
- BOOST_RESULT_OF_USE_TR1
, which causes
- result_of
to use the convention described
- above instead of decltype
.
-
This implementation of result_of
requires class template partial specialization, the
@@ -266,7 +266,7 @@ typedef boost::result_of<
N1836,
or, for motivation and design rationale,
the result_of
proposal.
- Contributed by Doug Gregor.
+ Created by Doug Gregor. Contributions from Daniel Walker, Eric Niebler, Michel Morin and others
Class templates for the Base-from-Member Idiom
See separate documentation.