Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
17858143
Commit
17858143
authored
Jan 15, 2021
by
Max Kellermann
Committed by
Max Kellermann
Jan 21, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/{Const,Writable}Buffer: enable `constexpr` on more methods
parent
c44a7b27
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
38 deletions
+16
-38
ConstBuffer.hxx
src/util/ConstBuffer.hxx
+9
-22
WritableBuffer.hxx
src/util/WritableBuffer.hxx
+7
-16
No files found.
src/util/ConstBuffer.hxx
View file @
17858143
...
@@ -137,10 +137,7 @@ struct ConstBuffer {
...
@@ -137,10 +137,7 @@ struct ConstBuffer {
* the assertion below ensures that the size is a multiple of
* the assertion below ensures that the size is a multiple of
* sizeof(T).
* sizeof(T).
*/
*/
#ifdef NDEBUG
constexpr
static
ConstBuffer
<
T
>
FromVoid
(
ConstBuffer
<
void
>
other
)
noexcept
{
constexpr
#endif
static
ConstBuffer
<
T
>
FromVoid
(
ConstBuffer
<
void
>
other
)
noexcept
{
static_assert
(
sizeof
(
T
)
>
0
,
"Empty base type"
);
static_assert
(
sizeof
(
T
)
>
0
,
"Empty base type"
);
#ifndef NDEBUG
#ifndef NDEBUG
assert
(
other
.
size
%
sizeof
(
T
)
==
0
);
assert
(
other
.
size
%
sizeof
(
T
)
==
0
);
...
@@ -170,8 +167,7 @@ struct ConstBuffer {
...
@@ -170,8 +167,7 @@ struct ConstBuffer {
}
}
template
<
typename
U
>
template
<
typename
U
>
gcc_pure
constexpr
bool
Contains
(
U
&&
u
)
const
noexcept
{
bool
Contains
(
U
&&
u
)
const
noexcept
{
for
(
const
auto
&
i
:
*
this
)
for
(
const
auto
&
i
:
*
this
)
if
(
u
==
i
)
if
(
u
==
i
)
return
true
;
return
true
;
...
@@ -195,10 +191,7 @@ struct ConstBuffer {
...
@@ -195,10 +191,7 @@ struct ConstBuffer {
return
data
+
size
;
return
data
+
size
;
}
}
#ifdef NDEBUG
constexpr
reference
operator
[](
size_type
i
)
const
noexcept
{
constexpr
#endif
reference
operator
[](
size_type
i
)
const
noexcept
{
#ifndef NDEBUG
#ifndef NDEBUG
assert
(
i
<
size
);
assert
(
i
<
size
);
#endif
#endif
...
@@ -210,10 +203,7 @@ struct ConstBuffer {
...
@@ -210,10 +203,7 @@ struct ConstBuffer {
* Returns a reference to the first element. Buffer must not
* Returns a reference to the first element. Buffer must not
* be empty.
* be empty.
*/
*/
#ifdef NDEBUG
constexpr
reference
front
()
const
noexcept
{
constexpr
#endif
reference
front
()
const
noexcept
{
#ifndef NDEBUG
#ifndef NDEBUG
assert
(
!
empty
());
assert
(
!
empty
());
#endif
#endif
...
@@ -224,10 +214,7 @@ struct ConstBuffer {
...
@@ -224,10 +214,7 @@ struct ConstBuffer {
* Returns a reference to the last element. Buffer must not
* Returns a reference to the last element. Buffer must not
* be empty.
* be empty.
*/
*/
#ifdef NDEBUG
constexpr
reference
back
()
const
noexcept
{
constexpr
#endif
reference
back
()
const
noexcept
{
#ifndef NDEBUG
#ifndef NDEBUG
assert
(
!
empty
());
assert
(
!
empty
());
#endif
#endif
...
@@ -238,7 +225,7 @@ struct ConstBuffer {
...
@@ -238,7 +225,7 @@ struct ConstBuffer {
* Remove the first element (by moving the head pointer, does
* Remove the first element (by moving the head pointer, does
* not actually modify the buffer). Buffer must not be empty.
* not actually modify the buffer). Buffer must not be empty.
*/
*/
void
pop_front
()
noexcept
{
constexpr
void
pop_front
()
noexcept
{
#ifndef NDEBUG
#ifndef NDEBUG
assert
(
!
empty
());
assert
(
!
empty
());
#endif
#endif
...
@@ -251,7 +238,7 @@ struct ConstBuffer {
...
@@ -251,7 +238,7 @@ struct ConstBuffer {
* Remove the last element (by moving the tail pointer, does
* Remove the last element (by moving the tail pointer, does
* not actually modify the buffer). Buffer must not be empty.
* not actually modify the buffer). Buffer must not be empty.
*/
*/
void
pop_back
()
noexcept
{
constexpr
void
pop_back
()
noexcept
{
#ifndef NDEBUG
#ifndef NDEBUG
assert
(
!
empty
());
assert
(
!
empty
());
#endif
#endif
...
@@ -263,13 +250,13 @@ struct ConstBuffer {
...
@@ -263,13 +250,13 @@ struct ConstBuffer {
* Remove the first element and return a reference to it.
* Remove the first element and return a reference to it.
* Buffer must not be empty.
* Buffer must not be empty.
*/
*/
reference
shift
()
noexcept
{
constexpr
reference
shift
()
noexcept
{
reference
result
=
front
();
reference
result
=
front
();
pop_front
();
pop_front
();
return
result
;
return
result
;
}
}
void
skip_front
(
size_type
n
)
noexcept
{
constexpr
void
skip_front
(
size_type
n
)
noexcept
{
#ifndef NDEBUG
#ifndef NDEBUG
assert
(
size
>=
n
);
assert
(
size
>=
n
);
#endif
#endif
...
...
src/util/WritableBuffer.hxx
View file @
17858143
...
@@ -188,10 +188,7 @@ struct WritableBuffer {
...
@@ -188,10 +188,7 @@ struct WritableBuffer {
return
data
+
size
;
return
data
+
size
;
}
}
#ifdef NDEBUG
constexpr
reference
operator
[](
size_type
i
)
const
noexcept
{
constexpr
#endif
reference
operator
[](
size_type
i
)
const
noexcept
{
#ifndef NDEBUG
#ifndef NDEBUG
assert
(
i
<
size
);
assert
(
i
<
size
);
#endif
#endif
...
@@ -203,10 +200,7 @@ struct WritableBuffer {
...
@@ -203,10 +200,7 @@ struct WritableBuffer {
* Returns a reference to the first element. Buffer must not
* Returns a reference to the first element. Buffer must not
* be empty.
* be empty.
*/
*/
#ifdef NDEBUG
constexpr
reference
front
()
const
noexcept
{
constexpr
#endif
reference
front
()
const
noexcept
{
#ifndef NDEBUG
#ifndef NDEBUG
assert
(
!
empty
());
assert
(
!
empty
());
#endif
#endif
...
@@ -217,10 +211,7 @@ struct WritableBuffer {
...
@@ -217,10 +211,7 @@ struct WritableBuffer {
* Returns a reference to the last element. Buffer must not
* Returns a reference to the last element. Buffer must not
* be empty.
* be empty.
*/
*/
#ifdef NDEBUG
constexpr
reference
back
()
const
noexcept
{
constexpr
#endif
reference
back
()
const
noexcept
{
#ifndef NDEBUG
#ifndef NDEBUG
assert
(
!
empty
());
assert
(
!
empty
());
#endif
#endif
...
@@ -231,7 +222,7 @@ struct WritableBuffer {
...
@@ -231,7 +222,7 @@ struct WritableBuffer {
* Remove the first element (by moving the head pointer, does
* Remove the first element (by moving the head pointer, does
* not actually modify the buffer). Buffer must not be empty.
* not actually modify the buffer). Buffer must not be empty.
*/
*/
void
pop_front
()
noexcept
{
constexpr
void
pop_front
()
noexcept
{
assert
(
!
empty
());
assert
(
!
empty
());
++
data
;
++
data
;
...
@@ -242,7 +233,7 @@ struct WritableBuffer {
...
@@ -242,7 +233,7 @@ struct WritableBuffer {
* Remove the last element (by moving the tail pointer, does
* Remove the last element (by moving the tail pointer, does
* not actually modify the buffer). Buffer must not be empty.
* not actually modify the buffer). Buffer must not be empty.
*/
*/
void
pop_back
()
noexcept
{
constexpr
void
pop_back
()
noexcept
{
assert
(
!
empty
());
assert
(
!
empty
());
--
size
;
--
size
;
...
@@ -252,13 +243,13 @@ struct WritableBuffer {
...
@@ -252,13 +243,13 @@ struct WritableBuffer {
* Remove the first element and return a reference to it.
* Remove the first element and return a reference to it.
* Buffer must not be empty.
* Buffer must not be empty.
*/
*/
reference
shift
()
noexcept
{
constexpr
reference
shift
()
noexcept
{
reference
result
=
front
();
reference
result
=
front
();
pop_front
();
pop_front
();
return
result
;
return
result
;
}
}
void
skip_front
(
size_type
n
)
noexcept
{
constexpr
void
skip_front
(
size_type
n
)
noexcept
{
#ifndef NDEBUG
#ifndef NDEBUG
assert
(
size
>=
n
);
assert
(
size
>=
n
);
#endif
#endif
...
...
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