I use the function read to read an integer from stdin
Why? What's wrong with using stream extraction?
At compile time, the type of T must be known - which isn't inferred from the return type. You can however specify a default type if none is specified. Eg:
template<class T = int>
You can also do this:
a = read<decltype(a)>();
which uses the defined type of a as the type T.
You can also use auto for the variable. Eg:
1 2
auto a {read<longlong>()};
auto i {read()}; // Assuming default template type specified
With C++20 it is possible to get a bit of narrowing for parameters with a single type when using the <concepts> library by specifying a core language concept.