C++ Library Extensions 2022.12.09
To help learn modern C++ programming
tpf::safe_type Namespace Reference

Defines safe type operation. More...

Namespaces

namespace  hidden
 

Functions

template<typename Type >
types::enable_if_integral_t< Type, int > count_set_bits (Type bits)
 Counts set bits. More...
 
template<typename Type >
types::enable_if_integral_t< Type, std::string > to_bits (Type bits)
 Returns binary bit pattern. More...
 
template<typename Type >
types::enable_if_integral_t< Type, std::string > to_hex (Type v)
 Returns hexidecimal representation. More...
 
template<typename Type >
types::enable_if_integral_t< Type, std::string > to_dec (Type v)
 Returns decimal representation. More...
 
template<typename Type >
types::enable_if_integral_t< Type, int > field_width (Type v)
 Returns' field width. More...
 
template<typename Type >
types::enable_if_integral_t< Type, int > numeric_width ()
 Return's maximum numeric field width. More...
 
template<typename Type >
types::enable_if_integral_t< Type, std::string > to_dec_width (Type v)
 Returns decimal field width. More...
 
template<typename Type >
types::enable_if_integral_t< Type, std::string > numeric_base (Type v)
 Displays how integral types are represented. More...
 
template<typename Type >
types::enable_if_integral_t< Type, std::string > numeric_type_info (Type)
 Displays integral type's numerical information. More...
 
template<typename = void>
void integral_type_info ()
 Displays all integral types' representation. More...
 
template<typename Type >
types::enable_if_integral_t< Type, void > twos_complement (Type c)
 Displays Twos complement. More...
 
template<typename Type >
types::enable_if_signed_integral_t< 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 > safe_sub (Type a, Type b)
 Safe subtraction of signed integral types. More...
 
template<typename Type >
types::enable_if_unsigned_integral_t< 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 > safe_sub (Type a, Type b)
 Safe subtraction of unsigned integral types. More...
 
template<typename Type >
types::enable_if_integral_t< Type > safe_mul (Type a, Type b)
 Safe multiplication of integral types. More...
 
template<typename Type >
types::enable_if_integral_t< Type > safe_div (Type a, Type b)
 Safe division of integral types. More...
 
template<typename Type >
types::enable_if_real_number_t< Type > safe_add (Type a, Type b)
 
template<typename Type >
types::enable_if_real_number_t< Type > safe_sub (Type a, Type b)
 
template<typename Type >
types::enable_if_real_number_t< Type > safe_mul (Type a, Type b)
 
template<typename Type >
types::enable_if_real_number_t< Type > safe_div (Type a, Type b)
 

Variables

template<typename Type >
constexpr Type limits_max
 Upperbound number the Type can represent. More...
 
template<typename Type >
constexpr Type limits_min
 Lowerbound number the Type can represent. More...
 
template<typename T >
constexpr int sizeof_bits = sizeof(T) * 8
 Returns bit count of type T. More...
 
template<typename T >
constexpr auto high_bit_mask
 Return's bit mask for the highest bit. More...
 

Detailed Description

Defines safe type operation.

Function Documentation

◆ count_set_bits()

template<typename Type >
types::enable_if_integral_t< Type, int > tpf::safe_type::count_set_bits ( Type  bits)

Counts set bits.

Template Parameters
Type
Parameters
bits
Returns
types::enable_if_integral_t<Type, int>

Definition at line 120 of file tpf_safe_type.hpp.

◆ field_width()

template<typename Type >
types::enable_if_integral_t< Type, int > tpf::safe_type::field_width ( Type  v)

Returns' field width.

Template Parameters
Type
Parameters
v
Returns
types::enable_if_integral_t<Type, int>

Definition at line 241 of file tpf_safe_type.hpp.

Here is the caller graph for this function:

◆ integral_type_info()

template<typename = void>
void tpf::safe_type::integral_type_info ( )

Displays all integral types' representation.

Definition at line 338 of file tpf_safe_type.hpp.

Here is the call graph for this function:

◆ numeric_base()

template<typename Type >
types::enable_if_integral_t< Type, std::string > tpf::safe_type::numeric_base ( Type  v)

Displays how integral types are represented.

Template Parameters
Type
Parameters
v
Returns
types::enable_if_integral_t<Type, std::string>

Definition at line 301 of file tpf_safe_type.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ numeric_type_info()

template<typename Type >
types::enable_if_integral_t< Type, std::string > tpf::safe_type::numeric_type_info ( Type  )

Displays integral type's numerical information.

Template Parameters
Type
Returns
types::enable_if_integral_t<Type, std::string>

Definition at line 318 of file tpf_safe_type.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ numeric_width()

template<typename Type >
types::enable_if_integral_t< Type, int > tpf::safe_type::numeric_width ( )

Return's maximum numeric field width.

Template Parameters
Type
Returns
types::enable_if_integral_t<Type, int>

Definition at line 261 of file tpf_safe_type.hpp.

Here is the call graph for this function:

◆ safe_add() [1/3]

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.

Template Parameters
Type
Parameters
a
b
Returns
types::enable_if_signed_integral_t<Type>

Definition at line 387 of file tpf_safe_type.hpp.

Here is the caller graph for this function:

◆ safe_add() [2/3]

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.

Template Parameters
Type
Parameters
a
b
Returns
types::enable_if_unsigned_integral_t<Type>

Definition at line 455 of file tpf_safe_type.hpp.

◆ safe_add() [3/3]

template<typename Type >
types::enable_if_real_number_t< Type > tpf::safe_type::safe_add ( Type  a,
Type  b 
)

Definition at line 554 of file tpf_safe_type.hpp.

◆ safe_div() [1/2]

template<typename Type >
types::enable_if_integral_t< Type > tpf::safe_type::safe_div ( Type  a,
Type  b 
)

Safe division of integral types.

Template Parameters
Type
Parameters
a
b
Returns
types::enable_if_integral_t<Type>

Definition at line 538 of file tpf_safe_type.hpp.

Here is the caller graph for this function:

◆ safe_div() [2/2]

template<typename Type >
types::enable_if_real_number_t< Type > tpf::safe_type::safe_div ( Type  a,
Type  b 
)

Definition at line 605 of file tpf_safe_type.hpp.

◆ safe_mul() [1/2]

template<typename Type >
types::enable_if_integral_t< Type > tpf::safe_type::safe_mul ( Type  a,
Type  b 
)

Safe multiplication of integral types.

Template Parameters
Type
Parameters
a
b
Returns
types::enable_if_integral_t<Type>

Definition at line 512 of file tpf_safe_type.hpp.

Here is the caller graph for this function:

◆ safe_mul() [2/2]

template<typename Type >
types::enable_if_real_number_t< Type > tpf::safe_type::safe_mul ( Type  a,
Type  b 
)

Definition at line 588 of file tpf_safe_type.hpp.

◆ safe_sub() [1/3]

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.

Template Parameters
Type
Parameters
a
b
Returns
types::enable_if_signed_integral_t<Type>

Definition at line 439 of file tpf_safe_type.hpp.

Here is the call graph for this function:

◆ safe_sub() [2/3]

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.

Template Parameters
Type
Parameters
a
b
Returns
types::enable_if_unsigned_integral_t<Type>

Definition at line 484 of file tpf_safe_type.hpp.

◆ safe_sub() [3/3]

template<typename Type >
types::enable_if_real_number_t< Type > tpf::safe_type::safe_sub ( Type  a,
Type  b 
)

Definition at line 571 of file tpf_safe_type.hpp.

◆ to_bits()

template<typename Type >
types::enable_if_integral_t< Type, std::string > tpf::safe_type::to_bits ( Type  bits)

Returns binary bit pattern.

Template Parameters
Type
Parameters
bits
Returns
types::enable_if_integral_t<Type, std::string>

Definition at line 141 of file tpf_safe_type.hpp.

◆ to_dec()

template<typename Type >
types::enable_if_integral_t< Type, std::string > tpf::safe_type::to_dec ( Type  v)

Returns decimal representation.

Template Parameters
Type
Parameters
v
Returns
types::enable_if_integral_t<Type, std::string>

Definition at line 220 of file tpf_safe_type.hpp.

◆ to_dec_width()

template<typename Type >
types::enable_if_integral_t< Type, std::string > tpf::safe_type::to_dec_width ( Type  v)

Returns decimal field width.

Template Parameters
Type
Parameters
v
Returns
types::enable_if_integral_t<Type, std::string>

Definition at line 278 of file tpf_safe_type.hpp.

Here is the caller graph for this function:

◆ to_hex()

template<typename Type >
types::enable_if_integral_t< Type, std::string > tpf::safe_type::to_hex ( Type  v)

Returns hexidecimal representation.

Template Parameters
Type
Parameters
v
Returns
types::enable_if_integral_t<Type, std::string>

Definition at line 167 of file tpf_safe_type.hpp.

◆ twos_complement()

template<typename Type >
types::enable_if_integral_t< Type, void > tpf::safe_type::twos_complement ( Type  c)

Displays Twos complement.

Template Parameters
Type
Parameters
c
Returns
types::enable_if_integral_t<Type, void>

Definition at line 363 of file tpf_safe_type.hpp.

Here is the call graph for this function:

Variable Documentation

◆ high_bit_mask

template<typename T >
constexpr auto tpf::safe_type::high_bit_mask
constexpr
Initial value:
=
hidden::unsigned_integral_t<T>(1) << (sizeof_bits<T>-1)

Return's bit mask for the highest bit.

Template Parameters
T

Definition at line 108 of file tpf_safe_type.hpp.

◆ limits_max

template<typename Type >
constexpr Type tpf::safe_type::limits_max
constexpr
Initial value:
=
std::numeric_limits<Type>::max()

Upperbound number the Type can represent.

Template Parameters
Type

Definition at line 53 of file tpf_safe_type.hpp.

◆ limits_min

template<typename Type >
constexpr Type tpf::safe_type::limits_min
constexpr
Initial value:
=
std::numeric_limits<Type>::min()

Lowerbound number the Type can represent.

Template Parameters
Type

Definition at line 61 of file tpf_safe_type.hpp.

◆ sizeof_bits

template<typename T >
constexpr int tpf::safe_type::sizeof_bits = sizeof(T) * 8
constexpr

Returns bit count of type T.

Template Parameters
Tfor querying bit count

Definition at line 100 of file tpf_safe_type.hpp.