BekTek said:
Could tell me more about that in detail?
Sure: I'm currently writing a book about the C++ library technical
report
(aka TR1) which includes 'std::tr1::function'. This is essentially just
'boost::function' but in another namespace
for example, in boost::function<int (char)> class it has typedef
function_return_type<R>::type internal_return_type;
First of all, 'internal_return_type' seems to be an implementation
detail
as far as I can tell, judging e.g. from the name of the type. It is, in
any case, not part of the TR1 specification. This has 'result_type' as
the only publically visible typedef.
But I think R is [int (char)], right?
I don't have the Boost implementation in front of me but I do have the
TR1
specification and this uses 'R' as the return type, e.g. in the form:
R(T1, T2, ..., TN)
Thus, I would guess that 'function_return_type<R>' somehow process the
function's return type to yield the actual return type (e.g. it might
add or remove a reference and/or const qualification). However, it is
rather unlikely that
function_return_type<R>::type
is identical to
R
How can [int (char)] be return type ?
In C++ it can't, at least it can't yet (maybe a future version of C++
support Lambda expression which would indeed yield function; currently
you can only create functor as is done by Boost's Lambda library). The
suitable return type is somehow deduced from 'R'. Assuming 'R' is
indeed
'int(char)', you can deduce the type from a class template like this:
template <typename T> struct function_return_type; // general version
template <typename R, T>
struct function_return_type<R(T)> { typedef R type; };
// more partial specializations, e.g. for function with more
arguments
If this is what 'function_return_type' does, it is much like TR1's
'result_of'.
the return type should be [int].. I
suppose..
.... and it probably is.
What treaks boost use in this case?
It probably uses partial specialization for 'function_return_type' to
yield the desired type (or some other type used internally by
'function_return_type').