FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
co-cpp19/src/array19.lib/array19/Array.h at develop · basicpp/co-cpp19 · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
basicpp
/
co-cpp19
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
14
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
co-cpp19
/
src
/
array19.lib
/
array19
/
Array.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (44 loc) · 2.35 KB
Breadcrumbs
co-cpp19
/
src
/
array19.lib
/
array19
/
Array.h
Copy path
File metadata and controls
57 lines (44 loc) · 2.35 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#
pragma
once
#
include
"
MoveSliceOf.h
"
#
include
"
SliceOf.h
"
#
include
<
stddef.h
>
//
size_t
namespace
array19
{
//
/ simplified version of std::array
//
/ * no member types
//
/ * no exceptions
template
<
class
T
,
size_t
C>
struct
Array
{
using
Element = T;
static
constexpr
auto
count = C;
T m[count];
bool
operator
==(
const
Array&)
const
=
default
;
[[nodiscard]]
constexpr
auto
isEmpty
()
const
noexcept
-> bool {
return
false
; }
[[nodiscard]]
constexpr
auto
begin
()
const
noexcept
->
const
T* {
return
m; }
[[nodiscard]]
constexpr
auto
end
()
const
noexcept
->
const
T* {
return
m + C; }
[[nodiscard]]
constexpr
auto
operator
[](
size_t
i)
const
noexcept
->
const
T& {
return
m[i]; }
[[nodiscard]]
constexpr
operator
SliceOf<
const
T>()
const
&
noexcept
{
return
SliceOf{m, C}; }
[[nodiscard]]
constexpr
auto
move
()
noexcept
-> MoveSliceOf<T> {
return
MoveSliceOf{m, C}; }
//
hint: use `amendSliceOfArray()` if you need to iterate and mutate
[[nodiscard]]
constexpr
auto
amendBegin
()
noexcept
-> T* {
return
m; }
[[nodiscard]]
constexpr
auto
amendEnd
()
noexcept
-> T* {
return
m + C; }
[[nodiscard]]
constexpr
auto
amend
()
noexcept
-> SliceOf<T> {
return
SliceOf{m, C}; }
};
template
<
class
T
>
struct
Array
<T,
0u
> {
using
Element = T;
static
constexpr
auto
count =
0u
;
bool
operator
==(
const
Array&)
const
=
default
;
[[nodiscard]]
constexpr
auto
isEmpty
()
const
noexcept
-> bool {
return
true
; }
[[nodiscard]]
constexpr
auto
begin
()
const
noexcept
->
const
T* {
return
nullptr
; }
[[nodiscard]]
constexpr
auto
end
()
const
noexcept
->
const
T* {
return
nullptr
; }
[[nodiscard]]
constexpr
operator
SliceOf<
const
T>()
const
&
noexcept
{
return
SliceOf{
begin
(),
0u
}; }
[[nodiscard]]
constexpr
auto
move
()
noexcept
-> MoveSliceOf<T> {
return
MoveSliceOf{
amendBegin
(),
0u
}; }
//
hint: use `amendSliceOfArray()` if you need to iterate and mutate
[[nodiscard]]
constexpr
auto
amendBegin
()
noexcept
-> T* {
return
nullptr
; }
[[nodiscard]]
constexpr
auto
amendEnd
()
noexcept
-> T* {
return
nullptr
; }
[[nodiscard]]
constexpr
auto
amend
()
noexcept
-> SliceOf<T> {
return
SliceOf{
amendBegin
(),
0u
}; }
};
//
/ simplified deduction guide
//
/ * not checking that all types are the same
//
/ usage:
//
/ Array{1, 2, 3};
template
<
class
T
,
class
... Ts>
Array
(T, Ts...) -> Array<T, 1 + sizeof...(Ts)>;
}
//
namespace array19
Back
|
FazBrowse Home
|
New Git URL