Here is the closest duplicate I could find.
Despite the tags, the question seems to be about C, and the usable answer references the C99 spec.
What is the correct way to handle this check in C++98, without using Boost or other libraries?
Copyright © 2021 Jogjafile Inc.
You can copy the code from
gsl::narrow()and tweak it slightly, turning it intocan_narrow()returning aboolrather thanthrowing: