|
Boost : |
From: Eric Niebler (eric_at_[hidden])
Date: 2007-01-14 01:17:58
Eric Niebler wrote:
> Tobias Schwinger wrote:
>> Hi,
>>
>> here is how it breaks.
>>
>> Let's start with the new bug:
>>
>> 1.
>>
>> typedef int (*func_ptr_0)();
>>
>> BOOST_STATIC_ASSERT((is_same<
>> result_of<func_ptr_0()>::type,
>> int>::value));
>>
>> ==> Ambiguous template specialization, this one got introduced by
>> Eric's workaround
>
> Yep, you're right. I hope find a fix before I leave for vacation on
> Monday. If I can't and this is a serious issue for you, feel free to
> revert the change until I can patch this up.
>
>
>> 2.
>>
>> Although it seems to be the same problem, it's actually a different
>> one (just a typo - see result_of_iterate.patch). This test fails with
>> the RC 1.34 version, too:
>>
>> typedef int (X::*mem_func_ptr_0)();
>>
>> BOOST_STATIC_ASSERT((is_same<
>> result_of<mem_func_ptr_0(X)>::type,
>> int>::value));
>
>
> I'll let Doug comment on this one.
The attached patch fixes both problems. Doug, should I commit (to HEAD)?
Also see the new test (attached).
-- Eric Niebler Boost Consulting www.boost-consulting.com
? boost/utility/result_of_patch.txt
Index: boost/utility/result_of.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/utility/result_of.hpp,v
retrieving revision 1.8
diff -b -d -u -r1.8 result_of.hpp
--- boost/utility/result_of.hpp 8 Jan 2007 20:38:51 -0000 1.8
+++ boost/utility/result_of.hpp 14 Jan 2007 06:13:50 -0000
@@ -31,6 +31,24 @@
template<typename F, typename FArgs, bool HasResultType> struct result_of_impl;
+template<typename F>
+struct result_of_void_impl
+{
+ typedef void type;
+};
+
+template<typename R>
+struct result_of_void_impl<R (*)(void)>
+{
+ typedef R type;
+};
+
+template<typename R>
+struct result_of_void_impl<R (&)(void)>
+{
+ typedef R type;
+};
+
template<typename F, typename FArgs>
struct result_of_impl<F, FArgs, true>
{
@@ -44,9 +62,8 @@
template<typename F>
struct result_of_impl<F, F(void), false>
-{
- typedef void type;
-};
+ : result_of_void_impl<F>
+{};
} // end namespace detail
Index: boost/utility/detail/result_of_iterate.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/utility/detail/result_of_iterate.hpp,v
retrieving revision 1.4
diff -b -d -u -r1.4 result_of_iterate.hpp
--- boost/utility/detail/result_of_iterate.hpp 8 Jan 2007 20:38:51 -0000 1.4
+++ boost/utility/detail/result_of_iterate.hpp 14 Jan 2007 06:13:50 -0000
@@ -24,25 +24,27 @@
: detail::result_of_impl<F, F(BOOST_RESULT_OF_ARGS), (detail::has_result_type<F>::value)> {};
#endif
+#undef BOOST_RESULT_OF_ARGS
+
+#if BOOST_PP_ITERATION() >= 1
+
namespace detail {
template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
-struct result_of_impl<R (*)(BOOST_RESULT_OF_ARGS), FArgs, false>
+struct result_of_impl<R (*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false>
{
typedef R type;
};
template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
-struct result_of_impl<R (&)(BOOST_RESULT_OF_ARGS), FArgs, false>
+struct result_of_impl<R (&)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false>
{
typedef R type;
};
-#undef BOOST_RESULT_OF_ARGS
-
-#if BOOST_PP_ITERATION() > 1 && !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
+#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
struct result_of_impl<R (T0::*)
@@ -84,3 +86,4 @@
#endif
}
+#endif
// Boost result_of library
// Copyright Douglas Gregor 2003-2004. Use, modification and
// distribution is 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)
// For more information, see http://www.boost.org/libs/utility
#include <boost/utility/result_of.hpp>
#include <utility>
#include <boost/static_assert.hpp>
#include <boost/type_traits/is_same.hpp>
struct int_result_type { typedef int result_type; };
struct int_result_of
{
template<typename F> struct result { typedef int type; };
};
struct int_result_type_and_float_result_of
{
typedef int result_type;
template<typename F> struct result { typedef float type; };
};
template<typename T>
struct int_result_type_template { typedef int result_type; };
template<typename T>
struct int_result_of_template
{
template<typename F> struct result;
template<typename This, typename That> struct result<This(That)> { typedef int type; };
};
template<typename T>
struct int_result_type_and_float_result_of_template
{
typedef int result_type;
template<typename F> struct result;
template<typename This, typename That> struct result<This(That)> { typedef float type; };
};
struct X {};
int main()
{
using namespace boost;
typedef int (*func_ptr)(float, double);
typedef int (&func_ref)(float, double);
typedef int (*func_ptr_0)();
typedef int (&func_ref_0)();
typedef int (X::*mem_func_ptr)(float);
typedef int (X::*mem_func_ptr_c)(float) const;
typedef int (X::*mem_func_ptr_v)(float) volatile;
typedef int (X::*mem_func_ptr_cv)(float) const volatile;
typedef int (X::*mem_func_ptr_0)();
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type(float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const int_result_of(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_and_float_result_of(char)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_template<void>(float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of_template<void>(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of_template<void>(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const int_result_of_template<void>(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of_template<void>(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_and_float_result_of_template<void>(char)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<func_ptr(char, float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<func_ref(char, float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<func_ptr_0()>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<func_ref_0()>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<mem_func_ptr(X,char)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<mem_func_ptr_c(X,char)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<mem_func_ptr_v(X,char)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<mem_func_ptr_cv(X,char)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<mem_func_ptr_0(X)>::type, int>::value));
return 0;
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk