Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
flatbuffers
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
flatbuffers
Commits
c7a797b9
Commit
c7a797b9
authored
Jun 04, 2018
by
Vladimir Glavnyy
Committed by
Wouter van Oortmerssen
Jun 04, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Makes VectorIterator compatible with STL iterators. (#4768)
parent
ecc07e77
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
4 deletions
+9
-4
flatbuffers.h
include/flatbuffers/flatbuffers.h
+2
-2
test.cpp
tests/test.cpp
+7
-2
No files found.
include/flatbuffers/flatbuffers.h
View file @
c7a797b9
...
...
@@ -91,7 +91,7 @@ template<typename T> struct IndirectHelper<const T *> {
template
<
typename
T
,
typename
IT
>
struct
VectorIterator
{
typedef
std
::
random_access_iterator_tag
iterator_category
;
typedef
IT
value_type
;
typedef
uoffset
_t
difference_type
;
typedef
ptrdiff
_t
difference_type
;
typedef
IT
*
pointer
;
typedef
IT
&
reference
;
...
...
@@ -121,7 +121,7 @@ template<typename T, typename IT> struct VectorIterator {
return
data_
!=
other
.
data_
;
}
ptrdiff_t
operator
-
(
const
VectorIterator
&
other
)
const
{
difference_type
operator
-
(
const
VectorIterator
&
other
)
const
{
return
(
data_
-
other
.
data_
)
/
IndirectHelper
<
T
>::
element_stride
;
}
...
...
tests/test.cpp
View file @
c7a797b9
...
...
@@ -273,8 +273,13 @@ void AccessFlatBufferTest(const uint8_t *flatbuf, size_t length,
TEST_EQ
(
VectorLength
(
inventory
),
10UL
);
// Works even if inventory is null.
TEST_NOTNULL
(
inventory
);
unsigned
char
inv_data
[]
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
};
for
(
auto
it
=
inventory
->
begin
();
it
!=
inventory
->
end
();
++
it
)
TEST_EQ
(
*
it
,
inv_data
[
it
-
inventory
->
begin
()]);
// Check compatibilty of iterators with STL.
std
::
vector
<
unsigned
char
>
inv_vec
(
inventory
->
begin
(),
inventory
->
end
());
for
(
auto
it
=
inventory
->
begin
();
it
!=
inventory
->
end
();
++
it
)
{
auto
indx
=
it
-
inventory
->
begin
();
TEST_EQ
(
*
it
,
inv_vec
.
at
(
indx
));
// Use bounds-check.
TEST_EQ
(
*
it
,
inv_data
[
indx
]);
}
TEST_EQ
(
monster
->
color
(),
Color_Blue
);
...
...
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