Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Maintenance - Mise à jour mensuelle Lundi 6 Février entre 7h00 et 9h00
Open sidebar
Gauthier Quesnel
irritator
Commits
6098bcfc
Commit
6098bcfc
authored
Apr 03, 2020
by
Gauthier Quesnel
Browse files
core: improve array container for no-POD data
parent
06217345
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/include/irritator/core.hpp
View file @
6098bcfc
...
...
@@ -1593,13 +1593,9 @@ template<typename T>
class
array
{
public:
static_assert
(
std
::
is_trivially_constructible_v
<
T
>
,
"array is only for POD object"
);
static_assert
(
std
::
is_trivially_destructible_v
<
T
>
,
"array is only for POD object"
);
using
value_type
=
T
;
using
reference
=
T
&
;
using
const_reference
=
const
T
&
;
using
pointer
=
T
*
;
using
difference_type
=
std
::
ptrdiff_t
;
using
size_type
=
std
::
size_t
;
...
...
@@ -1615,6 +1611,10 @@ public:
~
array
()
noexcept
{
if
constexpr
(
!
std
::
is_trivial_v
<
T
>
)
for
(
u32
i
=
0
;
i
!=
capacity
;
++
i
)
items
[
i
].
~
T
();
if
(
items
)
std
::
free
(
items
);
}
...
...
@@ -1625,10 +1625,21 @@ public:
return
status
::
block_allocator_bad_capacity
;
if
(
new_capacity
!=
capacity
)
{
if
(
items
)
std
::
free
(
items
);
items
=
static_cast
<
value_type
*>
(
std
::
malloc
(
new_capacity
*
sizeof
(
value_type
)));
if
(
items
)
{
if
constexpr
(
!
std
::
is_trivial_v
<
T
>
)
for
(
u32
i
=
0
;
i
!=
capacity
;
++
i
)
items
[
i
].
~
T
();
if
(
items
)
std
::
free
(
items
);
}
items
=
static_cast
<
value_type
*>
(
std
::
malloc
(
new_capacity
*
sizeof
(
value_type
)));
for
(
u32
i
=
0
;
i
!=
capacity
;
++
i
)
new
(
&
items
[
i
])
T
();
if
(
items
==
nullptr
)
return
status
::
block_allocator_not_enough_memory
;
}
...
...
@@ -1638,13 +1649,13 @@ public:
return
status
::
success
;
}
reference
operator
[](
differenc
e_type
i
)
noexcept
reference
operator
[](
siz
e_type
i
)
noexcept
{
assert
(
i
>=
0
&&
i
<
capacity
);
assert
(
i
<
capacity
);
return
items
[
i
];
}
reference
operator
[](
size_type
i
)
noexcept
const_
reference
operator
[](
size_type
i
)
const
noexcept
{
assert
(
i
<
capacity
);
return
items
[
i
];
...
...
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