Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
c30d06ea
Commit
c30d06ea
authored
Mar 31, 2017
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove C++14-isms (back to C++11).
parent
041401ba
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
19 deletions
+15
-19
common.h
c++/src/capnp/common.h
+4
-4
layout.h
c++/src/capnp/layout.h
+1
-5
units.h
c++/src/kj/units.h
+10
-10
No files found.
c++/src/capnp/common.h
View file @
c30d06ea
...
...
@@ -599,25 +599,25 @@ template <uint64_t requestedMax, typename T> inline constexpr uint unboundMax(T
template
<
uint
bits
,
typename
T
>
inline
constexpr
uint
unboundMaxBits
(
T
i
)
{
return
i
;
}
template
<
uint
newMax
,
typename
T
,
typename
ErrorFunc
>
inline
constexpr
T
assertMax
(
T
value
,
ErrorFunc
&&
func
)
{
inline
T
assertMax
(
T
value
,
ErrorFunc
&&
func
)
{
if
(
KJ_UNLIKELY
(
value
>
newMax
))
func
();
return
value
;
}
template
<
typename
T
,
typename
ErrorFunc
>
inline
constexpr
T
assertMax
(
uint
newMax
,
T
value
,
ErrorFunc
&&
func
)
{
inline
T
assertMax
(
uint
newMax
,
T
value
,
ErrorFunc
&&
func
)
{
if
(
KJ_UNLIKELY
(
value
>
newMax
))
func
();
return
value
;
}
template
<
uint
bits
,
typename
T
,
typename
ErrorFunc
=
ThrowOverflow
>
inline
constexpr
T
assertMaxBits
(
T
value
,
ErrorFunc
&&
func
=
ErrorFunc
())
{
inline
T
assertMaxBits
(
T
value
,
ErrorFunc
&&
func
=
ErrorFunc
())
{
if
(
KJ_UNLIKELY
(
value
>
kj
::
maxValueForBits
<
bits
>
()))
func
();
return
value
;
}
template
<
typename
T
,
typename
ErrorFunc
=
ThrowOverflow
>
inline
constexpr
T
assertMaxBits
(
uint
bits
,
T
value
,
ErrorFunc
&&
func
=
ErrorFunc
())
{
inline
T
assertMaxBits
(
uint
bits
,
T
value
,
ErrorFunc
&&
func
=
ErrorFunc
())
{
if
(
KJ_UNLIKELY
(
value
>
(
1ull
<<
bits
)
-
1
))
func
();
return
value
;
}
...
...
c++/src/capnp/layout.h
View file @
c30d06ea
...
...
@@ -104,11 +104,7 @@ inline KJ_CONSTEXPR() BitsPerElementTableType dataBitsPerElement(ElementSize siz
}
inline
constexpr
PointersPerElementN
<
1
>
pointersPerElement
(
ElementSize
size
)
{
if
(
size
==
ElementSize
::
POINTER
)
{
return
ONE
*
POINTERS
/
ELEMENTS
;
}
else
{
return
ZERO
*
POINTERS
/
ELEMENTS
;
}
return
size
==
ElementSize
::
POINTER
?
ONE
*
POINTERS
/
ELEMENTS
:
ZERO
*
POINTERS
/
ELEMENTS
;
}
static
constexpr
BitsPerElementTableType
BITS_PER_ELEMENT_INCLUDING_PONITERS_TABLE
[
8
]
=
{
...
...
c++/src/kj/units.h
View file @
c30d06ea
...
...
@@ -786,7 +786,7 @@ inline constexpr auto assumeMax(Quantity<BoundedConst<maxN>, Unit>, Quantity<Num
}
template
<
uint64_t
newMax
,
uint64_t
maxN
,
typename
T
,
typename
ErrorFunc
>
inline
constexpr
Bounded
<
newMax
,
T
>
assertMax
(
Bounded
<
maxN
,
T
>
value
,
ErrorFunc
&&
errorFunc
)
{
inline
Bounded
<
newMax
,
T
>
assertMax
(
Bounded
<
maxN
,
T
>
value
,
ErrorFunc
&&
errorFunc
)
{
// Assert that the bounded value is less than or equal to the given maximum, calling errorFunc()
// if not.
static_assert
(
newMax
<
maxN
,
"this bounded size assertion is redundant"
);
...
...
@@ -794,7 +794,7 @@ inline constexpr Bounded<newMax, T> assertMax(Bounded<maxN, T> value, ErrorFunc&
}
template
<
uint64_t
newMax
,
uint64_t
maxN
,
typename
T
,
typename
Unit
,
typename
ErrorFunc
>
inline
constexpr
Quantity
<
Bounded
<
newMax
,
T
>
,
Unit
>
assertMax
(
inline
Quantity
<
Bounded
<
newMax
,
T
>
,
Unit
>
assertMax
(
Quantity
<
Bounded
<
maxN
,
T
>
,
Unit
>
value
,
ErrorFunc
&&
errorFunc
)
{
// Assert that the bounded value is less than or equal to the given maximum, calling errorFunc()
// if not.
...
...
@@ -804,20 +804,20 @@ inline constexpr Quantity<Bounded<newMax, T>, Unit> assertMax(
}
template
<
uint
newMax
,
uint64_t
maxN
,
typename
T
,
typename
ErrorFunc
>
inline
constexpr
Bounded
<
newMax
,
T
>
assertMax
(
inline
Bounded
<
newMax
,
T
>
assertMax
(
BoundedConst
<
newMax
>
,
Bounded
<
maxN
,
T
>
value
,
ErrorFunc
&&
errorFunc
)
{
return
assertMax
<
newMax
>
(
value
,
kj
::
mv
(
errorFunc
));
}
template
<
uint
newMax
,
uint64_t
maxN
,
typename
T
,
typename
Unit
,
typename
ErrorFunc
>
inline
constexpr
Quantity
<
Bounded
<
newMax
,
T
>
,
Unit
>
assertMax
(
inline
Quantity
<
Bounded
<
newMax
,
T
>
,
Unit
>
assertMax
(
Quantity
<
BoundedConst
<
newMax
>
,
Unit
>
,
Quantity
<
Bounded
<
maxN
,
T
>
,
Unit
>
value
,
ErrorFunc
&&
errorFunc
)
{
return
assertMax
<
newMax
>
(
value
,
kj
::
mv
(
errorFunc
));
}
template
<
uint64_t
newBits
,
uint64_t
maxN
,
typename
T
,
typename
ErrorFunc
=
ThrowOverflow
>
inline
constexpr
Bounded
<
maxValueForBits
<
newBits
>
(),
T
>
assertMaxBits
(
inline
Bounded
<
maxValueForBits
<
newBits
>
(),
T
>
assertMaxBits
(
Bounded
<
maxN
,
T
>
value
,
ErrorFunc
&&
errorFunc
=
ErrorFunc
())
{
// Assert that the bounded value requires no more than the given number of bits, calling
// errorFunc() if not.
...
...
@@ -826,7 +826,7 @@ inline constexpr Bounded<maxValueForBits<newBits>(), T> assertMaxBits(
template
<
uint64_t
newBits
,
uint64_t
maxN
,
typename
T
,
typename
Unit
,
typename
ErrorFunc
=
ThrowOverflow
>
inline
constexpr
Quantity
<
Bounded
<
maxValueForBits
<
newBits
>
(),
T
>
,
Unit
>
assertMaxBits
(
inline
Quantity
<
Bounded
<
maxValueForBits
<
newBits
>
(),
T
>
,
Unit
>
assertMaxBits
(
Quantity
<
Bounded
<
maxN
,
T
>
,
Unit
>
value
,
ErrorFunc
&&
errorFunc
=
ErrorFunc
())
{
// Assert that the bounded value requires no more than the given number of bits, calling
// errorFunc() if not.
...
...
@@ -994,12 +994,12 @@ public:
inline
explicit
constexpr
SafeUnwrapper
(
Bounded
<
maxN
,
T
>
value
)
:
value
(
value
.
unwrap
())
{}
template
<
typename
U
,
typename
=
EnableIf
<
isIntegral
<
U
>
()
>>
inline
constexpr
operator
U
()
{
inline
constexpr
operator
U
()
const
{
static_assert
(
maxN
<=
U
(
maxValue
),
"possible truncation detected"
);
return
value
;
}
inline
constexpr
operator
bool
()
{
inline
constexpr
operator
bool
()
const
{
static_assert
(
maxN
<=
1
,
"possible truncation detected"
);
return
value
;
}
...
...
@@ -1019,12 +1019,12 @@ template <uint64_t value>
class
SafeConstUnwrapper
{
public
:
template
<
typename
T
,
typename
=
EnableIf
<
isIntegral
<
T
>
()
>>
inline
constexpr
operator
T
()
{
inline
constexpr
operator
T
()
const
{
static_assert
(
value
<=
T
(
maxValue
),
"this operation will truncate"
);
return
value
;
}
inline
constexpr
operator
bool
()
{
inline
constexpr
operator
bool
()
const
{
static_assert
(
value
<=
1
,
"this operation will truncate"
);
return
value
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment