There are known ways to manipulate the type of an integer literal
0L; // long
3U; // unsigned integer
1LL; // long long
What I need is a
Depending on the function, you may also be able to do this and may find it cleaner:
auto result = func(1, some_var);
For example, I've done this with std::max
:
auto result = std::max(0, std::min(index, vec.size()-1));
By explicitly specifying the template instantiation, the casts can be implicit. However, do note that this is a cast, so is susceptible to errors which Potatoswatter's brace initialization isn't.