![]() |
C++ Library Extensions 2022.12.09
To help learn modern C++ programming
|
This file implements safe arithmetic. More...
#include <iostream>
#include <type_traits>
#include <limits>
#include <string>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <tpf_types.hpp>
Go to the source code of this file.
Namespaces | |
namespace | tpf |
Includes subnamespace conversion. | |
namespace | tpf::safe_type |
Defines safe type operation. | |
namespace | tpf::safe_type::hidden |
Macros | |
#define | NOMINMAX |
Typedefs | |
template<typename T , typename = types::enable_if_integral_t<T>> | |
using | tpf::safe_type::hidden::unsigned_integral_t = types::make_unsigned_integral_t< T > |
template<typename T , typename = types::enable_if_integral_t<T>> | |
using | tpf::safe_type::hidden::signed_integral_t = types::make_signed_integral_t< T > |
template<typename S , typename T > | |
using | tpf::safe_type::hidden::common_t = types::common_type_t< S, T > |
template<typename S , typename T , typename = types::enable_if_integral_t<S>, typename = types::enable_if_integral_t<T>> | |
using | tpf::safe_type::hidden::signed_common_t = signed_integral_t< common_t< S, T > > |
template<typename S , typename T , typename = types::enable_if_integral_t<S>, typename = types::enable_if_integral_t<T>> | |
using | tpf::safe_type::hidden::unsigned_common_t = unsigned_integral_t< common_t< S, T > > |
Functions | |
template<typename Type > | |
types::enable_if_integral_t< Type, int > | tpf::safe_type::count_set_bits (Type bits) |
Counts set bits. More... | |
template<typename Type > | |
types::enable_if_integral_t< Type, std::string > | tpf::safe_type::to_bits (Type bits) |
Returns binary bit pattern. More... | |
template<typename Type > | |
types::enable_if_integral_t< Type, std::string > | tpf::safe_type::to_hex (Type v) |
Returns hexidecimal representation. More... | |
template<typename Type > | |
types::enable_if_integral_t< Type, std::string > | tpf::safe_type::to_dec (Type v) |
Returns decimal representation. More... | |
template<typename Type > | |
types::enable_if_integral_t< Type, int > | tpf::safe_type::field_width (Type v) |
Returns' field width. More... | |
template<typename Type > | |
types::enable_if_integral_t< Type, int > | tpf::safe_type::numeric_width () |
Return's maximum numeric field width. More... | |
template<typename Type > | |
types::enable_if_integral_t< Type, std::string > | tpf::safe_type::to_dec_width (Type v) |
Returns decimal field width. More... | |
template<typename Type > | |
types::enable_if_integral_t< Type, std::string > | tpf::safe_type::numeric_base (Type v) |
Displays how integral types are represented. More... | |
template<typename Type > | |
types::enable_if_integral_t< Type, std::string > | tpf::safe_type::numeric_type_info (Type) |
Displays integral type's numerical information. More... | |
template<typename = void> | |
void | tpf::safe_type::integral_type_info () |
Displays all integral types' representation. More... | |
template<typename Type > | |
types::enable_if_integral_t< Type, void > | tpf::safe_type::twos_complement (Type c) |
Displays Twos complement. More... | |
template<typename Type > | |
types::enable_if_signed_integral_t< Type > | tpf::safe_type::safe_add (Type a, Type b) |
Safe addition of the signed integral types. More... | |
template<typename Type > | |
types::enable_if_signed_integral_t< Type > | tpf::safe_type::safe_sub (Type a, Type b) |
Safe subtraction of signed integral types. More... | |
template<typename Type > | |
types::enable_if_unsigned_integral_t< Type > | tpf::safe_type::safe_add (Type a, Type b) |
Safe addition of the unsigned integral types. More... | |
template<typename Type > | |
types::enable_if_unsigned_integral_t< Type > | tpf::safe_type::safe_sub (Type a, Type b) |
Safe subtraction of unsigned integral types. More... | |
template<typename Type > | |
types::enable_if_integral_t< Type > | tpf::safe_type::safe_mul (Type a, Type b) |
Safe multiplication of integral types. More... | |
template<typename Type > | |
types::enable_if_integral_t< Type > | tpf::safe_type::safe_div (Type a, Type b) |
Safe division of integral types. More... | |
template<typename Type > | |
types::enable_if_real_number_t< Type > | tpf::safe_type::safe_add (Type a, Type b) |
template<typename Type > | |
types::enable_if_real_number_t< Type > | tpf::safe_type::safe_sub (Type a, Type b) |
template<typename Type > | |
types::enable_if_real_number_t< Type > | tpf::safe_type::safe_mul (Type a, Type b) |
template<typename Type > | |
types::enable_if_real_number_t< Type > | tpf::safe_type::safe_div (Type a, Type b) |
Variables | |
template<typename Type > | |
constexpr Type | tpf::safe_type::limits_max |
Upperbound number the Type can represent. More... | |
template<typename Type > | |
constexpr Type | tpf::safe_type::limits_min |
Lowerbound number the Type can represent. More... | |
template<typename T > | |
constexpr int | tpf::safe_type::sizeof_bits = sizeof(T) * 8 |
Returns bit count of type T. More... | |
template<typename T > | |
constexpr auto | tpf::safe_type::high_bit_mask |
Return's bit mask for the highest bit. More... | |
This file implements safe arithmetic.
Definition in file tpf_safe_type.hpp.
#define NOMINMAX |
Definition at line 15 of file tpf_safe_type.hpp.