------- Comment #2 from potswa at mac dot com 2010-05-17 06:06 -------
Sorry, that was completely wrong. I thought I'd isolated a testcase with the
above code plus int main() { return rcv_f<decltype(f)>(f); }, but that actually
does work.
It seems the problem is completely different. The testcase below suggests that
decltype somehow cannot recurse in the presence of a reference to function
type.
#include <tuple>
#include <type_traits> // aside: std::result_of belongs in <type_traits>
#include <functional> // not <functional>.
template< class T, class F,
size_t tuple_index0 = std::tuple_size<T>::value,
size_t... tuple_indexes >
typename std::result_of< typename std::enable_if< tuple_index0 == 0,
F( typename std::tuple_element< tuple_indexes - 1, T >::type... )
>::type >::type
apply( T const &t, F f ) {
return f( std::get< tuple_indexes - 1 >( t )... );
}
template< class T, class F,
size_t tuple_index0 = std::tuple_size<T>::value,
size_t... tuple_indexes >
decltype( apply< typename std::enable_if< tuple_index0 != 0, T >::type,
F, tuple_index0 - 1, tuple_index0, tuple_indexes... >
( std::declval<T>(), std::declval<F>() ) )
apply( T const &t, F f ) {
return apply< T, F, tuple_index0 - 1, tuple_index0, tuple_indexes... >
( t, f );
}
void f() {}
void g( int ) {}
void h( int, int ) {}
struct a { void operator()( int, int ) {} };
int main() {
// these cases work:
apply( std::make_tuple(), f );
apply( std::make_tuple( 0 ), g );
apply< std::tuple< int, int >, void (&)(int, int), 1, 2 >( std::make_tuple(
0, 0 ), h );
apply( std::make_tuple( 0, 0 ), a() );
// this does not:
apply( std::make_tuple( 0, 0 ), h );
}
Either the subject of this bug should be changed or I should open a new bug.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44162