bux API Reference
1.11.0
Static library of whatever are seen required in general purpose but not directly supported from Modern C++. Or whatever reusable originated from my side projects.
Toggle main menu visibility
Main Page
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
i
l
m
o
p
r
s
t
u
Functions
_
a
b
c
d
e
f
g
i
l
o
p
r
s
t
u
Variables
Typedefs
Enumerations
Enumerator
Concepts
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
a
b
c
d
e
f
g
i
l
m
n
o
p
r
s
t
u
v
~
Functions
a
b
c
d
e
f
g
i
l
m
n
o
p
r
s
t
u
v
~
Variables
m
t
Typedefs
Related Symbols
Files
File List
File Members
All
_
c
d
f
h
l
o
r
s
t
Functions
Typedefs
Macros
_
c
d
f
h
l
r
s
t
Examples
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Concepts
Loading...
Searching...
No Matches
include
bux
SafeArith.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <limits>
// std::numeric_limits<>
4
5
namespace
bux
{
6
7
//
8
// Types
9
//
10
namespace
Helper_
{
11
12
template
<
bool
FLAG_
signed
,
class
T>
13
struct
C_NoWrap
14
{
15
static
T
add
(T a, T b);
16
};
13
struct
C_NoWrap
{
…
};
17
18
template
<
bool
FLAG_
int
eger,
bool
FLAG_
signed
,
bool
FLAG_overflow,
class
T>
19
struct
C_CmpRet
20
{
21
static
inline
int
cast
(T a)
22
{
return
a < T()? -1: a > T() ?1: 0; }
21
static
inline
int
cast
(T a) {
…
}
23
};
19
struct
C_CmpRet
{
…
};
24
25
}
// namespace Helper_
10
namespace
Helper_
{
…
}
26
27
//
28
// Function Templates
29
//
30
template
<
class
T>
31
inline
T
addNoWrap
(T a, T b)
32
{
33
return
Helper_::C_NoWrap<std::numeric_limits<T>::is_signed
,T>::add(a, b);
34
}
31
inline
T
addNoWrap
(T a, T b) {
…
}
35
36
template
<
class
T>
37
inline
int
compareReturn
(T a)
38
{
39
return
Helper_::C_CmpRet
<
40
std::numeric_limits<T>::is_integer,
41
std::numeric_limits<T>::is_signed,
42
(std::numeric_limits<T>::radix == std::numeric_limits<int>::radix &&
43
std::numeric_limits<T>::digits > std::numeric_limits<int>::digits),
44
T>::cast(a);
45
}
37
inline
int
compareReturn
(T a) {
…
}
46
47
//
48
// Specialize class templates
49
//
50
namespace
Helper_ {
51
52
template
<
class
T>
53
struct
C_NoWrap
<true,T>
54
{
55
static
T
add
(T a, T b)
56
{
57
const
bool
aneg =a < T();
58
const
bool
bneg =b < T();
59
if
(aneg != bneg)
60
return
T(a +b);
61
62
if
(aneg)
63
return
std::numeric_limits<T>::min() -a < b? T(a +b):
64
std::numeric_limits<T>::min();
65
66
// a == 0 || b == 0 is considered a rare case
67
return
std::numeric_limits<T>::max() -a > b? T(a +b):
68
std::numeric_limits<T>::max();
69
}
55
static
T
add
(T a, T b) {
…
}
70
};
53
struct
C_NoWrap
<true,T> {
…
};
71
72
template
<
class
T>
73
struct
C_NoWrap
<false,T>
74
{
75
static
T
add
(T a, T b)
76
{
77
return
T(std::numeric_limits<T>::max() -a) > b? T(a +b):
78
std::numeric_limits<T>::max();
79
}
75
static
T
add
(T a, T b) {
…
}
80
};
73
struct
C_NoWrap
<false,T> {
…
};
81
82
template
<
bool
FLAG_
signed
,
class
T>
83
struct
C_CmpRet
<true,FLAG_signed,false,T>
84
{
85
static
inline
int
cast
(T a)
86
{
return
int
(a); }
85
static
inline
int
cast
(T a) {
…
}
87
};
83
struct
C_CmpRet
<true,FLAG_signed,false,T> {
…
};
88
89
template
<
bool
FLAG_
int
eger,
bool
FLAG_overflow,
class
T>
90
struct
C_CmpRet
<FLAG_integer,false,FLAG_overflow,T>
91
{
92
static
inline
int
cast
(T a)
93
{
return
a != T()? 1: 0; }
92
static
inline
int
cast
(T a) {
…
}
94
};
90
struct
C_CmpRet
<FLAG_integer,false,FLAG_overflow,T> {
…
};
95
96
}
// namespace Helper_
97
98
}
//namespace bux
int
bux::Helper_
Definition
SafeArith.h:10
bux
THE common namespace of bux library.
Definition
AtomiX.cpp:3
bux::compareReturn
int compareReturn(T a)
Definition
SafeArith.h:37
bux::addNoWrap
T addNoWrap(T a, T b)
Definition
SafeArith.h:31
bux::Helper_::C_CmpRet< FLAG_integer, false, FLAG_overflow, T >::cast
static int cast(T a)
Definition
SafeArith.h:92
bux::Helper_::C_CmpRet< true, FLAG_signed, false, T >::cast
static int cast(T a)
Definition
SafeArith.h:85
bux::Helper_::C_CmpRet
Definition
SafeArith.h:20
bux::Helper_::C_CmpRet::cast
static int cast(T a)
Definition
SafeArith.h:21
bux::Helper_::C_NoWrap< false, T >::add
static T add(T a, T b)
Definition
SafeArith.h:75
bux::Helper_::C_NoWrap< true, T >::add
static T add(T a, T b)
Definition
SafeArith.h:55
bux::Helper_::C_NoWrap
Definition
SafeArith.h:14
bux::Helper_::C_NoWrap::add
static T add(T a, T b)
Generated by
1.13.2