Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gauthier Quesnel
irritator
Commits
921e7b54
Commit
921e7b54
authored
May 11, 2020
by
Gauthier Quesnel
Browse files
core: add resize member
parent
7090552a
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/include/irritator/core.hpp
View file @
921e7b54
...
...
@@ -1690,33 +1690,42 @@ public:
vector
(
vector
&&
)
noexcept
=
delete
;
vector
&
operator
=
(
vector
&&
)
noexcept
=
delete
;
status
init
(
std
::
size_t
new_capacity
)
noexcept
status
init
(
std
::
size_t
new_capacity
_
)
noexcept
{
if
(
new_capacity
>
std
::
numeric_limits
<
unsigned
>::
max
())
if
(
new_capacity
_
>
std
::
numeric_limits
<
unsigned
>::
max
())
return
status
::
vector_init_capacity_too_big
;
if
(
new_capacity
==
0
)
if
(
new_capacity
_
==
0
)
return
status
::
vector_init_capacity_zero
;
if
(
new_capacity
!=
m_capacity
)
{
if
(
m_items
)
{
if
constexpr
(
!
std
::
is_trivial_v
<
T
>
)
for
(
auto
i
=
0u
;
i
!=
m_size
;
++
i
)
m_items
[
i
].
~
T
();
clear
();
if
(
m_items
)
std
::
free
(
m_items
);
}
const
auto
new_capacity
=
static_cast
<
unsigned
int
>
(
new_capacity_
);
if
(
new_capacity
>
m_capacity
)
{
if
(
m_items
)
std
::
free
(
m_items
);
m_items
=
static_cast
<
value_type
*>
(
std
::
malloc
(
new_capacity
*
sizeof
(
value_type
)));
if
(
m_items
==
nullptr
)
return
status
::
vector_init_not_enough_memory
;
m_capacity
=
new_capacity
;
}
m_capacity
=
static_cast
<
unsigned
>
(
new_capacity
);
m_size
=
0
;
return
status
::
success
;
}
status
resize
(
std
::
size_t
new_capacity_
)
noexcept
{
static_assert
(
std
::
is_trivial_v
<
T
>
,
"vector::resize only for trivial data"
);
irt_return_if_bad
(
init
(
new_capacity_
));
m_size
=
m_capacity
;
return
status
::
success
;
}
...
...
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