Skip to content
Snippets Groups Projects
Commit d519913c authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[IO] Add is_safely_convertable().

This checks for possible overflows for two
arbitrary types.
parent 4b35be2a
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,19 @@
#include "MeshLib/Elements/Tet.h"
#include "MeshLib/Elements/Tri.h"
// Check if the value can by converted to given type without overflow.
template <typename VALUE, typename TYPE>
bool
is_safely_convertable(VALUE const& value)
{
bool const result = value <= std::numeric_limits<TYPE>::max();
if (!result) {
ERR("The value %d is too large for conversion.", value);
ERR("Maximum available size is %d.", std::numeric_limits<TYPE>::max());
}
return result;
}
namespace FileIO
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment