Implementation, tests and first use of rangechecked_cast
This commit is contained in:
parent
c5f6da48ce
commit
f875f0f012
8 changed files with 61 additions and 5 deletions
15
core/rangechecked_cast.h
Normal file
15
core/rangechecked_cast.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef RANGECHECKED_CAST_H
|
||||
#define RANGECHECKED_CAST_H
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <limits>
|
||||
|
||||
template <typename To, typename From>
|
||||
To rangechecked_cast(From f)
|
||||
{
|
||||
BOOST_ASSERT(f > std::numeric_limits<To>::lowest());
|
||||
BOOST_ASSERT(f < std::numeric_limits<To>::max());
|
||||
return static_cast<To>(f);
|
||||
}
|
||||
|
||||
#endif // RANGECHECKED_CAST_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue