Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
1cac6d48
Commit
1cac6d48
authored
May 14, 2020
by
Eugene Kosov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
span cleanup
parent
af784385
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
21 deletions
+41
-21
include/span.h
include/span.h
+41
-21
No files found.
include/span.h
View file @
1cac6d48
...
...
@@ -24,11 +24,33 @@ this program; if not, write to the Free Software Foundation, Inc.,
namespace
st_
{
namespace
detail
{
template
<
class
T
>
struct
remove_cv
{
typedef
T
type
;
};
template
<
class
T
>
struct
remove_cv
<
const
T
>
{
typedef
T
type
;
};
template
<
class
T
>
struct
remove_cv
<
volatile
T
>
{
typedef
T
type
;
};
template
<
class
T
>
struct
remove_cv
<
const
volatile
T
>
{
typedef
T
type
;
};
}
// namespace detail
template
<
class
ElementType
>
class
span
{
public:
typedef
ElementType
element_type
;
typedef
ElementT
ype
value_type
;
typedef
typename
detail
::
remove_cv
<
ElementType
>::
t
ype
value_type
;
typedef
size_t
size_type
;
typedef
ptrdiff_t
difference_type
;
typedef
element_type
*
pointer
;
...
...
@@ -38,7 +60,6 @@ template <class ElementType> class span
typedef
pointer
iterator
;
typedef
const_pointer
const_iterator
;
typedef
std
::
reverse_iterator
<
iterator
>
reverse_iterator
;
typedef
std
::
reverse_iterator
<
const_iterator
>
const_reverse_iterator
;
span
()
:
data_
(
NULL
),
size_
(
0
)
{}
...
...
@@ -64,73 +85,72 @@ template <class ElementType> class span
span
&
operator
=
(
const
span
&
other
)
{
data_
=
other
.
data
_
;
size_
=
other
.
size
_
;
data_
=
other
.
data
()
;
size_
=
other
.
size
()
;
return
*
this
;
}
template
<
size_t
Count
>
span
<
element_type
>
first
()
const
{
assert
(
!
empty
());
return
span
(
data
_
,
1
);
return
span
(
data
()
,
1
);
}
template
<
size_t
Count
>
span
<
element_type
>
last
()
const
{
assert
(
!
empty
());
return
span
(
data
_
+
size
()
-
1
,
1
);
return
span
(
data
()
+
size
()
-
1
,
1
);
}
span
<
element_type
>
first
(
size_type
count
)
const
{
assert
(
!
empty
());
return
span
(
data
_
,
1
);
return
span
(
data
()
,
1
);
}
span
<
element_type
>
last
(
size_type
count
)
const
{
assert
(
!
empty
());
return
span
(
data
_
+
size
()
-
1
,
1
);
return
span
(
data
()
+
size
()
-
1
,
1
);
}
span
<
element_type
>
subspan
(
size_type
offset
,
size_type
count
)
const
{
assert
(
!
empty
());
assert
(
size
()
>=
offset
+
count
);
return
span
(
data
_
+
offset
,
count
);
return
span
(
data
()
+
offset
,
count
);
}
size_type
size
()
const
{
return
size_
;
}
size_type
size_bytes
()
const
{
return
size_
*
sizeof
(
ElementType
);
}
bool
empty
()
const
__attribute__
((
warn_unused_result
))
{
return
size_
==
0
;
}
size_type
size_bytes
()
const
{
return
size
()
*
sizeof
(
ElementType
);
}
bool
empty
()
const
__attribute__
((
warn_unused_result
))
{
return
size
()
==
0
;
}
reference
operator
[](
size_type
idx
)
const
{
assert
(
size
()
>
idx
);
return
data
_
[
idx
];
return
data
()
[
idx
];
}
reference
front
()
const
{
assert
(
!
empty
());
return
data
_
[
0
];
return
data
()
[
0
];
}
reference
back
()
const
{
assert
(
!
empty
());
return
data_
[
size
()
-
1
];
}
pointer
data
()
const
{
assert
(
!
empty
());
return
data_
;
return
data
()[
size
()
-
1
];
}
pointer
data
()
const
{
return
data_
;
}
iterator
begin
()
const
{
return
data_
;
}
iterator
end
()
const
{
return
data_
+
size_
;
}
reverse_iterator
rbegin
()
const
{
return
std
::
reverse_iterator
<
iterator
>
(
std
::
advance
(
end
(),
-
1
));
return
std
::
reverse_iterator
<
iterator
>
(
end
(
));
}
reverse_iterator
rend
()
const
{
return
std
::
reverse_iterator
<
iterator
>
(
std
::
advance
(
begin
(),
-
1
));
return
std
::
reverse_iterator
<
iterator
>
(
begin
(
));
}
private:
...
...
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