Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
000f704e
Commit
000f704e
authored
Jan 10, 2019
by
Mark OLESEN
Browse files
ENH: FixedList empty(), size(), max_size() now constexpr static (
#1160
)
- this allows their use as templates parameters
parent
c52d70cc
Changes
3
Hide whitespace changes
Inline
Side-by-side
applications/test/FixedList/Test-FixedList.C
View file @
000f704e
...
...
@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation |
Copyright (C) 2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
...
...
@@ -68,6 +68,36 @@ Ostream& printInfo
}
template
<
class
T
,
unsigned
N
>
void
compileInfo
()
{
// Info<< typeid(decltype(FixedList<T, N>)).name() << nl;
// Info<< " holds: "
// << typeid(decltype(FixedList<T, N>::value_type())).name() << nl;
Info
<<
"max_size:"
<<
FixedList
<
T
,
N
>::
max_size
()
<<
nl
;
}
template
<
class
FixedListType
>
typename
std
::
enable_if
<
(
FixedListType
::
max_size
()
==
2
),
bool
>::
type
is_pair
()
{
return
true
;
}
template
<
class
FixedListType
>
typename
std
::
enable_if
<
(
FixedListType
::
max_size
()
!=
2
),
std
::
string
>::
type
is_pair
()
{
return
"not really at all"
;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
...
...
@@ -86,6 +116,18 @@ int main(int argc, char *argv[])
args
.
found
(
"default"
)
||
args
.
options
().
empty
();
typedef
FixedList
<
scalar
,
2
>
scalar2Type
;
typedef
FixedList
<
label
,
3
>
label3Type
;
// Compile-time info
compileInfo
<
label
,
5
>
();
Info
<<
"pair: "
<<
is_pair
<
scalar2Type
>
()
<<
nl
;
Info
<<
"pair: "
<<
is_pair
<
label3Type
>
()
<<
nl
;
Info
<<
"max_size:"
<<
scalar2Type
::
max_size
()
<<
nl
;
if
(
defaultTests
||
args
.
found
(
"iter"
))
{
Info
<<
nl
...
...
src/OpenFOAM/containers/Lists/FixedList/FixedList.H
View file @
000f704e
...
...
@@ -90,7 +90,7 @@ protected:
// Protected Member Functions
//- True if there are two or more entries and all entries have
//
identical values.
//
-
identical values.
inline
bool
uniform
()
const
;
//- Write the FixedList with its compound type
...
...
@@ -99,7 +99,7 @@ protected:
public:
// STL
t
ype
d
efinitions
// STL
T
ype
D
efinitions
//- The value type the FixedList contains
typedef
T
value_type
;
...
...
@@ -197,16 +197,16 @@ public:
// This can be used (with caution) when interfacing with C code
inline
T
*
data
();
//-
Return t
he first element of the list
//-
T
he first element of the list
, position [0]
inline
T
&
first
();
//-
Return
first element of the list
//-
The
first element of the list
, position [0]
inline
const
T
&
first
()
const
;
//-
Return t
he last element of the list
//-
T
he last element of the list
, position [N-1]
inline
T
&
last
();
//-
Return t
he last element of the list
//-
T
he last element of the list
, position [N-1]
inline
const
T
&
last
()
const
;
...
...
@@ -279,7 +279,7 @@ public:
inline
void
transfer
(
FixedList
<
T
,
N
>&
list
);
// Member
o
perators
// Member
O
perators
//- Return element of FixedList
inline
T
&
operator
[](
const
label
i
);
...
...
@@ -357,22 +357,22 @@ public:
inline
const_reverse_iterator
rend
()
const
;
// STL
m
ember
f
unctions
// STL
M
ember
F
unctions
//-
Return the number of elements in the FixedList
inline
label
size
()
const
;
//-
Always false since zero-sized FixedList is compile-time disabled.
static
constexpr
bool
empty
()
noexcept
{
return
!
N
;
}
//- Return
size of the largest possibl
e FixedList
inline
label
max_
size
()
const
;
//- Return
the number of elements in th
e FixedList
static
constexpr
label
size
()
noexcept
{
return
N
;
}
//-
Always false since zero-sized FixedList is compile-time disabled.
inline
bool
empty
()
const
;
//-
The dimensioned size (template parameter N) of the FixedList
static
constexpr
unsigned
max_size
()
noexcept
{
return
N
;
}
//- Swap lists by swapping the content of the individual list elements
inline
void
swap
(
FixedList
<
T
,
N
>&
list
);
// STL
m
ember
o
perators
// STL
M
ember
O
perators
//- Equality operation on FixedLists of the same type.
// Returns true when the FixedLists are element-wise equal
...
...
src/OpenFOAM/containers/Lists/FixedList/FixedListI.H
View file @
000f704e
...
...
@@ -548,27 +548,6 @@ Foam::FixedList<T, N>::crend() const
}
template
<
class
T
,
unsigned
N
>
inline
Foam
::
label
Foam
::
FixedList
<
T
,
N
>::
size
()
const
{
return
N
;
}
template
<
class
T
,
unsigned
N
>
inline
Foam
::
label
Foam
::
FixedList
<
T
,
N
>::
max_size
()
const
{
return
N
;
}
template
<
class
T
,
unsigned
N
>
inline
bool
Foam
::
FixedList
<
T
,
N
>::
empty
()
const
{
return
false
;
}
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
template
<
class
T
,
unsigned
N
>
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment