Variable template type

Viewed 83

Just want to confirm that type of templated variable can be independent of template. This compiles by g++:

template<class T> 
constexpr long MAX_AS_LONG = static_cast<long>(std::numeric_limits<T>::max());

Does it confirm to the standard?

(In all the examples on the internet, type of templated variable is T itself).

1 Answers

There is no requirement the type of a template variable differs based on template arguments.

A common example is std::is_same_v<T,U> which is always a bool.

Related