Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
biboumi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
88
Issues
88
List
Boards
Labels
Service Desk
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
louiz’
biboumi
Commits
7f08cf83
Commit
7f08cf83
authored
Feb 15, 2017
by
louiz’
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Little scopeguard cleanup, and add a test
parent
fa6635e5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
4 deletions
+17
-4
louloulibs/utils/encoding.cpp
louloulibs/utils/encoding.cpp
+2
-2
louloulibs/utils/scopeguard.hpp
louloulibs/utils/scopeguard.hpp
+4
-2
tests/utils.cpp
tests/utils.cpp
+11
-0
No files found.
louloulibs/utils/encoding.cpp
View file @
7f08cf83
...
...
@@ -152,7 +152,7 @@ namespace utils
throw
std
::
runtime_error
(
"Cannot convert into UTF-8"
);
// Make sure cd is always closed when we leave this function
const
auto
sg
=
utils
::
make_scope_guard
([
&
cd
](
auto
&&
){
iconv_close
(
cd
);
});
const
auto
sg
=
utils
::
make_scope_guard
([
&
cd
](){
iconv_close
(
cd
);
});
size_t
inbytesleft
=
str
.
size
();
...
...
@@ -169,7 +169,7 @@ namespace utils
char
*
outbuf_ptr
=
outbuf
;
// Make sure outbuf is always deleted when we leave this function
const
auto
sg2
=
utils
::
make_scope_guard
([
outbuf
](
auto
&&
){
delete
[]
outbuf
;
});
const
auto
sg2
=
utils
::
make_scope_guard
([
outbuf
](){
delete
[]
outbuf
;
});
bool
done
=
false
;
while
(
done
==
false
)
...
...
louloulibs/utils/scopeguard.hpp
View file @
7f08cf83
...
...
@@ -87,9 +87,11 @@ private:
};
template
<
typename
F
>
auto
make_scope_guard
(
F
&&
f
)
auto
make_scope_guard
(
F
f
)
{
return
std
::
unique_ptr
<
void
,
std
::
decay_t
<
F
>>
{(
void
*
)
1
,
std
::
forward
<
F
>
(
f
)};
static
struct
Empty
{}
empty
;
auto
deleter
=
[
f
=
std
::
move
(
f
)](
Empty
*
)
{
f
();
};
return
std
::
unique_ptr
<
Empty
,
decltype
(
deleter
)
>
{
&
empty
,
std
::
move
(
deleter
)};
}
}
...
...
tests/utils.cpp
View file @
7f08cf83
...
...
@@ -8,6 +8,7 @@
#include <utils/empty_if_fixed_server.hpp>
#include <utils/get_first_non_empty.hpp>
#include <utils/time.hpp>
#include <utils/scopeguard.hpp>
using
namespace
std
::
string_literals
;
...
...
@@ -140,3 +141,13 @@ TEST_CASE("parse_datetime")
CHECK
(
utils
::
parse_datetime
(
"1970-01-02T00:00:12*00:00"
)
==
-
1
);
CHECK
(
utils
::
parse_datetime
(
"1970-01-02T00:00:12+0000"
)
==
-
1
);
}
TEST_CASE
(
"scope_guard"
)
{
bool
res
=
false
;
{
auto
guard
=
utils
::
make_scope_guard
([
&
res
](){
res
=
true
;
});
CHECK
(
!
res
);
}
CHECK
(
res
);
}
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