In C++11 you can use decltype
like this:
template <typename tuple_holder_type, typename B>
auto
func(tuple_holder_type h, B b)
-> decltype(std::tuple_cat(h.a,std::make_tuple(b)))
{
return std::tuple_cat(h.a,std::make_tuple(b));
}
In the C++1y working draft, you can drop the decltype
like this:
template <typename tuple_holder_type, typename B>
auto
func(tuple_holder_type h, B b)
{
return std::tuple_cat(h.a,std::make_tuple(b));
}
And here is how you can get the return type of func
and put it in a typedef
, no matter how func
's return type is coded:
template <typename tuple_holder_type, typename B>
struct tuple_appender {
typedef decltype(func(std::declval<typename tuple_holder_type::tuple_type>(),
std::declval<std::tuple<B>>())) return_type;
};
std::declval<T>()
is just a way to get an rvalue expression of type T
without having to default construct one, like T()
. You may not want to assume that T
is default constructible. You can also get an lvalue expression of T
with declval<T&>()
, or a const lvalue expression with declval<const T&>()
, etc.