CBMC
narrow.h File Reference
#include <type_traits>
#include "invariant.h"
+ Include dependency graph for narrow.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename output_type , typename input_type >
output_type narrow_cast (input_type value)
 Alias for static_cast intended to be used for numeric casting Rationale: Easier to grep than static_cast. More...
 
template<typename output_type , typename input_type >
output_type narrow (input_type input)
 Run-time checked narrowing cast. More...
 
template<typename output_type , typename input_type >
output_type narrow_or_throw_out_of_range (input_type input)
 Run-time checked narrow cast. More...
 

Function Documentation

◆ narrow()

template<typename output_type , typename input_type >
output_type narrow ( input_type  input)

Run-time checked narrowing cast.

Raises an invariant if the input value cannot be converted to the output value without data loss

Template accepts a single argument - the return type. Input type is deduced from the function argument and shouldn't be specified

Definition at line 34 of file narrow.h.

◆ narrow_cast()

template<typename output_type , typename input_type >
output_type narrow_cast ( input_type  value)

Alias for static_cast intended to be used for numeric casting Rationale: Easier to grep than static_cast.

Definition at line 19 of file narrow.h.

◆ narrow_or_throw_out_of_range()

template<typename output_type , typename input_type >
output_type narrow_or_throw_out_of_range ( input_type  input)

Run-time checked narrow cast.

Throws a std::out_of_range error if the input cannot be converted to the output_type without data lass

Definition at line 44 of file narrow.h.