Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
amdis-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
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
amdis
amdis-core
Commits
aa317187
Commit
aa317187
authored
5 years ago
by
Praetorius, Simon
Browse files
Options
Downloads
Patches
Plain Diff
make AllTrueBitSetVector an infinite range
parent
d4b9a66f
No related branches found
Branches containing commit
No related tags found
1 merge request
!100
Added extended AllTrueBitSetVector class
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/amdis/utility/AllTrueBitSetVector.hpp
+54
-16
54 additions, 16 deletions
src/amdis/utility/AllTrueBitSetVector.hpp
test/AllTrueBitSetVectorTest.cpp
+36
-0
36 additions, 0 deletions
test/AllTrueBitSetVectorTest.cpp
test/CMakeLists.txt
+3
-0
3 additions, 0 deletions
test/CMakeLists.txt
with
93 additions
and
16 deletions
src/amdis/utility/AllTrueBitSetVector.hpp
+
54
−
16
View file @
aa317187
#pragma once
#include
<cstddef>
#include
<iterator>
namespace
AMDiS
{
/// \brief Vector-like container of bools returning always true
/// \brief Vector-like container of bools returning always true.
/**
* Model of an infinite range of bools of value `true` with vector-like element
* access by `operator[]`.
**/
class
AllTrueBitSetVector
{
public:
using
value_type
=
bool
;
struct
const_iterator
{
constexpr
const_iterator
(
bool
sentinel
=
false
)
noexcept
:
sentinel_
(
sentinel
)
{}
using
value_type
=
bool
;
using
reference
=
bool
;
using
difference_type
=
std
::
ptrdiff_t
;
using
iterator_category
=
std
::
forward_iterator_tag
;
constexpr
bool
operator
*
()
const
noexcept
{
return
true
;
}
constexpr
const_iterator
&
operator
++
()
noexcept
{
return
*
this
;
}
constexpr
const_iterator
operator
++
(
int
)
noexcept
{
return
*
this
;
}
/// Comparison of the iterator is always true if both are sentinel or both are const_iterator
friend
constexpr
bool
operator
==
(
const_iterator
a
,
const_iterator
b
)
noexcept
{
return
a
.
sentinel_
==
b
.
sentinel_
;
}
bool
sentinel_
=
false
;
/// Comparison of the iterator is always true
constexpr
bool
operator
==
(
const_iterator
)
const
noexcept
{
return
true
;
}
constexpr
bool
operator
!=
(
const_iterator
)
const
noexcept
{
return
false
;
}
};
/// Constexpr default constructor
constexpr
AllTrueBitSetVector
()
noexcept
=
default
;
public
:
// element access
/// Converting to true
constexpr
operator
bool
()
const
noexcept
{
return
true
;
}
/// Access any element of the container return
ing
always true.
/// Access
to
any element of the container return
s
always true.
template
<
class
Index
>
constexpr
const
AllTrueBitSetVector
&
operator
[](
Index
const
&
/*index*/
)
const
noexcept
constexpr
AllTrueBitSetVector
const
&
at
(
Index
const
&
/*index*/
)
const
noexcept
{
return
*
this
;
}
/// Access to any element of the container returns always true.
template
<
class
Index
>
constexpr
AllTrueBitSetVector
const
&
operator
[](
Index
const
&
/*index*/
)
const
noexcept
{
return
*
this
;
}
/// Access the front element of the infinite range
constexpr
AllTrueBitSetVector
const
&
front
()
const
noexcept
{
return
*
this
;
}
public
:
// iterators
/// Return iterator that always redirects to a bool true.
constexpr
const_iterator
begin
()
const
noexcept
{
return
const_iterator
{
false
};
}
constexpr
const_iterator
end
()
const
noexcept
{
return
const_iterator
{
true
};
}
constexpr
const_iterator
begin
()
const
noexcept
{
return
const_iterator
{};
}
/// Return iterator that always redirects to a bool true.
constexpr
const_iterator
cbegin
()
const
noexcept
{
return
const_iterator
{
false
};
}
constexpr
const_iterator
cend
()
const
noexcept
{
return
const_iterator
{
true
};
}
constexpr
const_iterator
cbegin
()
const
noexcept
{
return
const_iterator
{};
}
public
:
// capacity and modifier
/// Resize does nothing
template
<
class
Size
>
constexpr
void
resize
(
Size
const
&
/*size*/
)
const
noexcept
{
/* do nothing */
}
constexpr
void
resize
(
Size
const
&
/*size*/
)
const
noexcept
{
/* do nothing */
}
/// The container is always non-empty
constexpr
bool
empty
()
const
noexcept
{
return
false
;
}
};
}
// end namespace AMDiS
This diff is collapsed.
Click to expand it.
test/AllTrueBitSetVectorTest.cpp
0 → 100644
+
36
−
0
View file @
aa317187
#include
<type_traits>
#include
<amdis/utility/AllTrueBitSetVector.hpp>
#include
"Tests.hpp"
using
namespace
AMDiS
;
int
main
(
int
argc
,
char
**
argv
)
{
constexpr
auto
bitSet
=
AllTrueBitSetVector
{};
// The bitset is not empty
AMDIS_TEST
(
!
bitSet
.
empty
());
// All entries are true
std
::
size_t
i
=
0
;
for
(
auto
it
=
bitSet
.
begin
();
i
<
10
;
++
it
,
++
i
)
AMDIS_TEST
(
*
it
);
for
(
i
=
0
;
i
<
10
;
++
i
)
{
AMDIS_TEST
(
bitSet
[
i
]);
AMDIS_TEST
(
bitSet
.
at
(
i
));
}
// The front entry is true
AMDIS_TEST
(
bitSet
.
front
());
// resize has not effect
bitSet
.
resize
(
0
);
AMDIS_TEST
(
!
bitSet
.
empty
());
// use bitset element as template parameter
auto
iconst
=
std
::
integral_constant
<
bool
,
bitSet
[
0
]
>
{};
return
report_errors
();
}
This diff is collapsed.
Click to expand it.
test/CMakeLists.txt
+
3
−
0
View file @
aa317187
...
...
@@ -5,6 +5,9 @@ dune_add_test(SOURCES AccessTest.cpp
dune_add_test
(
SOURCES AdaptInfoTest.cpp
LINK_LIBRARIES amdis
)
dune_add_test
(
SOURCES AllTrueBitSetVectorTest.cpp
LINK_LIBRARIES amdis
)
foreach
(
_GRID RANGE 7
)
dune_add_test
(
NAME
"BackupRestoreTest_
${
_GRID
}
"
SOURCES BackupRestoreTest.cpp
...
...
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