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
4b0d1632
Commit
4b0d1632
authored
May 14, 2017
by
Mark OLESEN
Browse files
BUG: hashtable key_iterator ++ operator returning incorrect type
ENH: ensure std::distance works with hashtable iterators
parent
0c53a815
Changes
3
Hide whitespace changes
Inline
Side-by-side
applications/test/HashTable/Test-hashTable.C
View file @
4b0d1632
...
...
@@ -25,6 +25,8 @@ License
#include
"HashTable.H"
#include
"List.H"
#include
"SortableList.H"
#include
"DynamicList.H"
#include
"FlatOutput.H"
#include
"IOstreams.H"
#include
"IStringStream.H"
...
...
@@ -194,7 +196,24 @@ int main()
// These do not yet work. Issues resolving the distance.
//
// List<scalar> table1vals(table1.begin(), table1.end());
// wordList table1keys(table1.begin(), table1.end());
{
Info
<<
"distance/size: "
<<
std
::
distance
(
table1
.
begin
(),
table1
.
end
())
<<
"/"
<<
table1
.
size
()
<<
" and "
<<
std
::
distance
(
table1
.
keys
().
begin
(),
table1
.
keys
().
end
())
<<
"/"
<<
table1
.
keys
().
size
()
<<
nl
;
SortableList
<
word
>
sortKeys
// DynamicList<word> sortKeys
(
table1
.
keys
().
begin
(),
table1
.
keys
().
end
()
);
Info
<<
"sortKeys: "
<<
flatOutput
(
sortKeys
)
<<
nl
;
}
Info
<<
"
\n
From table1: "
<<
flatOutput
(
table1
.
sortedToc
())
<<
nl
<<
"retain keys: "
<<
flatOutput
(
table3
.
sortedToc
())
<<
nl
;
...
...
src/OpenFOAM/containers/HashTables/HashTable/HashTable.H
View file @
4b0d1632
...
...
@@ -61,6 +61,7 @@ SourceFiles
#include
"nullObject.H"
#include
<initializer_list>
#include
<iterator>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...
...
@@ -179,10 +180,17 @@ public:
//- Type of values that the HashTable contains.
typedef
T
value_type
;
//- The type used for storing into value_type objects.
// This type is usually value_type&.
typedef
T
*
pointer
;
//- The type used for storing into value_type objects.
// This type is usually value_type&.
typedef
T
&
reference
;
//- The type used for reading from constant value_type objects.
typedef
const
T
*
const_pointer
;
//- The type used for reading from constant value_type objects.
typedef
const
T
&
const_reference
;
...
...
@@ -441,6 +449,7 @@ protected:
// Public typedefs
using
table_type
=
this_type
;
using
key_type
=
this_type
::
key_type
;
using
iterator_category
=
std
::
forward_iterator_tag
;
using
difference_type
=
this_type
::
difference_type
;
private:
...
...
@@ -518,16 +527,20 @@ public:
public
WrappedIterator
{
public:
using
value_type
=
this_type
::
key_type
;
using
pointer
=
const
Key
*
;
using
reference
=
const
Key
&
;
using
difference_type
=
typename
WrappedIterator
::
difference_type
;
//- Implicit conversion
inline
key_iterator_base
(
const
WrappedIterator
&
iter
);
//- Return the key
inline
reference
operator
*
()
const
;
}
;
inline
reference
operator
()()
const
;
inline
key_iterator_base
&
operator
++
();
inline
key_iterator_base
operator
++
(
int
);
};
// STL iterator
...
...
@@ -544,9 +557,9 @@ public:
// Public typedefs
using
table_type
=
this_type
;
using
key_type
=
this_type
::
key_type
;
using
value_type
=
this_type
::
value_type
;
using
pointer
=
this_type
::
pointer
;
using
reference
=
this_type
::
reference
;
using
difference_type
=
typename
iterator_base
::
difference_type
;
// Constructors
...
...
@@ -592,9 +605,9 @@ public:
// Public typedefs
using
table_type
=
const
this_type
;
using
key_type
=
this_type
::
key_type
;
using
value_type
=
const
this_type
::
value_type
;
using
pointer
=
this_type
::
const_pointer
;
using
reference
=
this_type
::
const_reference
;
using
difference_type
=
typename
iterator_base
::
difference_type
;
// Constructors
...
...
src/OpenFOAM/containers/HashTables/HashTable/HashTableI.H
View file @
4b0d1632
...
...
@@ -363,6 +363,39 @@ Foam::HashTable<T, Key, Hash>::key_iterator_base<WrappedIterator>
}
template
<
class
T
,
class
Key
,
class
Hash
>
template
<
class
WrappedIterator
>
inline
const
Key
&
Foam
::
HashTable
<
T
,
Key
,
Hash
>::
key_iterator_base
<
WrappedIterator
>
::
operator
()()
const
{
return
this
->
key
();
}
template
<
class
T
,
class
Key
,
class
Hash
>
template
<
class
WrappedIterator
>
inline
Foam
::
HashTable
<
T
,
Key
,
Hash
>::
key_iterator_base
<
WrappedIterator
>&
Foam
::
HashTable
<
T
,
Key
,
Hash
>::
key_iterator_base
<
WrappedIterator
>
::
operator
++
()
{
this
->
increment
();
return
*
this
;
}
template
<
class
T
,
class
Key
,
class
Hash
>
template
<
class
WrappedIterator
>
inline
Foam
::
HashTable
<
T
,
Key
,
Hash
>::
key_iterator_base
<
WrappedIterator
>
Foam
::
HashTable
<
T
,
Key
,
Hash
>::
key_iterator_base
<
WrappedIterator
>
::
operator
++
(
int
)
{
key_iterator_base
old
=
*
this
;
this
->
increment
();
return
old
;
}
// * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
template
<
class
T
,
class
Key
,
class
Hash
>
...
...
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