Index: rtorrent/rak/functional_fun.h =================================================================== --- rtorrent/rak/functional_fun.h (revision 682) +++ rtorrent/rak/functional_fun.h (working copy) @@ -343,34 +343,44 @@ return new value_fn0_t(val); } +template +struct equal_types_t { + typedef A first_type; + typedef B second_type; + + const static int result = 0; +}; + +template +struct equal_types_t { + typedef A first_type; + typedef A second_type; + + const static int result = 1; +}; + template inline function_base0* convert_fn(function_base0* src) { - return new convert_fn0_t(src); + if (equal_types_t, function_base0 >::result) + // The pointer cast never gets done if the types are different, + // but needs to be here to pleasant the compiler. + return reinterpret_cast, function_base0 >::first_type*>(src); + else + return new convert_fn0_t(src); } -// This overload ensures that if we try to convert to the same type, -// it will optimize away the unneeded layer. -template -inline function_base0* -convert_fn(function_base0* src) { - return src; -} - template inline function_base1* convert_fn(function_base1* src) { - return new convert_fn1_t(src); + if (equal_types_t, function_base1 >::result) + // The pointer cast never gets done if the types are different, + // but needs to be here to pleasant the compiler. + return reinterpret_cast, function_base1 >::first_type*>(src); + else + return new convert_fn1_t(src); } -// This overload ensures that if we try to convert to the same type, -// it will optimize away the unneeded layer. -template -inline function_base1* -convert_fn(function_base1* src) { - return src; } -} - #endif