I've been playing with the problem too, and found this solution...it
does not rely on typeof, but it does rely on return_type. I'm a bit
unsure about why I had to use "unsigned int" to make it work, so I'd
welcome some comments on this.
Do you mean you couldn't use RetType properly? I've tried with
the following in GCC 3.2:
template
struct extract_and_call {
typedef RetType result_type;
RetType operator()(T const& t) const {
return ((t .* MemberPtr) .* MemberFct)();
}
};
Aye, I got the following warning that I could not get rid of (VC 7.1)
C:\Boost\include\boost-1_33_1\boost\functional\hash\hash.hpp(132) :
warning C4267: 'argument' : conversion from 'size_t' to 'unsigned int',
possible loss of data
Complete error (warning) message:
C:\Boost\include\boost-1_33_1\boost\functional\hash\hash.hpp(132) :
error C2220: warning treated as error - no object file generated
C:\Boost\include\boost-1_33_1\boost\functional\hash\hash.hpp(130) :
while compiling class-template member function 'size_t
boost::hash_detail::call_hash<T>::call(const T &)'
with
[
T=extract_and_call::size_type,std::basic_string::size_type
std::basic_string::size(void)
const>::result_type
]
C:\Boost\include\boost-1_33_1\boost\functional\hash\hash.hpp(315) : see
reference to class template instantiation
'boost::hash_detail::call_hash<T>' being compiled
with
[
T=extract_and_call::size_type,std::basic_string::size_type
std::basic_string::size(void)
const>::result_type
]
C:\Boost\include\boost-1_33_1\boost\functional\hash\hash.hpp(314) :
while compiling class-template member function 'size_t
boost::hash<T>::operator ()(const T &) const'
with
[
T=extract_and_call::size_type,std::basic_string::size_type
std::basic_string::size(void)
const>::result_type
]
C:\Boost\include\boost-1_33_1\boost\multi_index\hashed_index.hpp(980) :
see reference to class template instantiation 'boost::hash<T>' being
compiled
with
[
T=extract_and_call::size_type,std::basic_string::size_type
std::basic_string::size(void) const>::result_type
]
C:\Boost\include\boost-1_33_1\boost\multi_index_container.hpp(80) : see
reference to class template instantiation
'boost::multi_index::detail::hashed_index'
being compiled
with
[
KeyFromValue=boost::multi_index::hashed_unique::size_type,std::basic_string::size_type
std::basic_string::size(void)
const>>::key_from_value_type,
Hash=boost::multi_index::hashed_unique::size_type,std::basic_string::size_type
std::basic_string::size(void)
const>>::hash_type,
Pred=boost::multi_index::hashed_unique::size_type,std::basic_string::size_type
std::basic_string::size(void)
const>>::pred_type,
SuperMeta=boost::multi_index::detail::nth_layer<1,foo,boost::multi_index::indexed_by::size_type,std::basic_string::size_type
std::basic_string::size(void)
const>>,boost::multi_index::ordered_unique::siz
e_type,std::basic_string::size_type
std::basic_string::size(void)
const>>>,std::allocator<foo>>,
TagList=boost::multi_index::hashed_unique::size_type,std::basic_string::size_type
std::basic_string::size(void)
const>>::tag_list_type,
Category=boost::multi_index::detail::hashed_unique_tag
]
LCS.cpp(94) : see reference to class template instantiation
'boost::multi_index::multi_index_container'
being compiled
with
[
Value=foo,
IndexSpecifierList=boost::multi_index::indexed_by::size_type,std::basic_string::size_type
std::basic_string::size(void)
const>>,boost::multi_index::ordered_unique::size_type,std::basic_string::size_type
std::basic_string::size(void)
const>>>
]
C:\Boost\include\boost-1_33_1\boost\functional\hash\hash.hpp(132) :
warning C4267: 'argument' : conversion from 'size_t' to 'unsigned int',
possible loss of data
Cheers,
Filip