Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Core Modules
dune-common
Commits
1cec2fe5
Commit
1cec2fe5
authored
2 years ago
by
Simon Praetorius
Browse files
Options
Downloads
Patches
Plain Diff
Add more constructors for the ReservedVector
parent
919365fc
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1158
Fillin missing functionality in ReservedVector and make it constexpr
Pipeline
#53023
passed
2 years ago
Stage: .pre
Stage: test
Stage: downstream
Pipeline: Dune Nightly Test
#53024
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dune/common/reservedvector.hh
+28
-5
28 additions, 5 deletions
dune/common/reservedvector.hh
dune/common/test/reservedvectortest.cc
+10
-0
10 additions, 0 deletions
dune/common/test/reservedvectortest.cc
with
38 additions
and
5 deletions
dune/common/reservedvector.hh
+
28
−
5
View file @
1cec2fe5
...
...
@@ -76,14 +76,33 @@ namespace Dune
/** @{ Constructors */
//!
Default Constru
ctor
//!
Constructs an empty ve
ctor
constexpr
ReservedVector
()
noexcept
(
std
::
is_nothrow_default_constructible_v
<
value_type
>
)
:
storage_
()
,
size_
(
0
)
{}
//! Constructor from an iterator range
//! Constructs the vector with `count` elements that will be default-initialized.
explicit
constexpr
ReservedVector
(
size_type
count
)
noexcept
(
std
::
is_nothrow_default_constructible_v
<
value_type
>
)
:
storage_
()
,
size_
(
count
)
{
assert
(
count
<=
n
);
}
//! Constructs the vector with `count` copies of elements with value `value`.
constexpr
ReservedVector
(
size_type
count
,
const
value_type
&
value
)
noexcept
(
std
::
is_nothrow_copy_assignable_v
<
value_type
>
&&
noexcept
(
ReservedVector
(
count
)))
:
ReservedVector
(
count
)
{
for
(
size_type
i
=
0
;
i
<
count
;
++
i
)
storage_
[
i
]
=
value
;
}
//! Constructs the vector from an iterator range `[first,last)`
template
<
class
InputIt
,
std
::
enable_if_t
<
std
::
is_convertible_v
<
typename
std
::
iterator_traits
<
InputIt
>
::
value_type
,
value_type
>
,
int
>
=
0
>
constexpr
ReservedVector
(
InputIt
first
,
InputIt
last
)
...
...
@@ -96,7 +115,7 @@ namespace Dune
assert
(
first
==
last
);
}
//! Constructor from an initializer list
//! Construct
s the vect
or from an initializer list
constexpr
ReservedVector
(
std
::
initializer_list
<
value_type
>
const
&
l
)
noexcept
(
std
::
is_nothrow_copy_assignable_v
<
value_type
>
&&
noexcept
(
ReservedVector
(
l
.
begin
(),
l
.
end
())))
...
...
@@ -107,7 +126,7 @@ namespace Dune
/** @{ Comparison */
//! Compares the values in the vector for equality
//! Compares the values in the vector
`this` with `that`
for equality
constexpr
bool
operator
==
(
const
ReservedVector
&
that
)
const
noexcept
{
if
(
size
()
!=
that
.
size
())
...
...
@@ -118,12 +137,13 @@ namespace Dune
return
true
;
}
//! Compares the values in the vector `this` with `that` for not equality
constexpr
bool
operator
!=
(
const
ReservedVector
&
that
)
const
noexcept
{
return
!
(
*
this
==
that
);
}
//! Lexicographically compares the values in the vector
//! Lexicographically compares the values in the vector
`this` with `that`
constexpr
bool
operator
<
(
const
ReservedVector
&
that
)
const
noexcept
{
for
(
size_type
i
=
0
;
i
<
std
::
min
(
size
(),
that
.
size
());
++
i
)
{
...
...
@@ -133,16 +153,19 @@ namespace Dune
return
size
()
<
that
.
size
();
}
//! Lexicographically compares the values in the vector `this` with `that`
constexpr
bool
operator
>
(
const
ReservedVector
&
that
)
const
noexcept
{
return
that
<
*
this
;
}
//! Lexicographically compares the values in the vector `this` with `that`
constexpr
bool
operator
<=
(
const
ReservedVector
&
that
)
const
noexcept
{
return
!
(
*
this
>
that
);
}
//! Lexicographically compares the values in the vector `this` with `that`
constexpr
bool
operator
>=
(
const
ReservedVector
&
that
)
const
noexcept
{
return
!
(
*
this
<
that
);
...
...
This diff is collapsed.
Click to expand it.
dune/common/test/reservedvectortest.cc
+
10
−
0
View file @
1cec2fe5
...
...
@@ -85,6 +85,16 @@ int main() {
rv2
[
3
]
==
4
&&
rv2
[
4
]
==
5
);
// check size constructor
Dune
::
ReservedVector
<
unsigned
int
,
8
>
rv3
(
7
);
test
.
check
(
rv3
.
size
()
==
7
);
test
.
check
(
rv3
[
6
]
==
0
);
// check size and value constructor
Dune
::
ReservedVector
<
unsigned
int
,
8
>
rv4
(
5
,
42
);
test
.
check
(
rv4
.
size
()
==
5
);
test
.
check
(
rv4
[
3
]
==
42
);
// check pop_back
rv2
.
pop_back
();
test
.
check
(
rv2
.
size
()
==
4
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment