Say I have a template class that has to work with general types T complex and real but I also need a real type that I can store the abs(T) in. How do I get the appropriate type and make a type definition?
I tried the following:
template < typename T>
class sth{
typedef std::invoke_result<*std::abs, Value>::type real_type;
real_type sth_else(T x)
return std::abs(f(x));
}
If you need to define in through result of expression, then it would be something like
using real_type = decltype (std::abs(std::declval<T>()));
declval
would provide a proper argument of type T to function
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.