How do I know if qualifiers like const
etc are associated with the passed arguments to a function?
eg
template<class T>
void callback(T & data)
{
body of function
}
How do I know if the data is const
etc?
You can test whether a type (including a template type argument) is const qualified using a standard type trait:
bool is_const = std::is_const_v<T>;
If T
is const qualified, then and only then is T&
a reference to const.
Whether or not the referred object is const is something that cannot be inspected.
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.