Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qthing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
qthing
Commits
728ea54a
Commit
728ea54a
authored
4 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Add callback template
parent
c7e2e46e
No related branches found
No related tags found
1 merge request
!16
Merge dev branch into master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
qthing/include/qthing/callback.hpp
+35
-0
35 additions, 0 deletions
qthing/include/qthing/callback.hpp
with
35 additions
and
0 deletions
qthing/include/qthing/callback.hpp
0 → 100644
+
35
−
0
View file @
728ea54a
#pragma once
#include
<functional>
namespace
qthing
{
template
<
typename
...
Args
>
class
Callback
{
private:
using
CallbackType
=
std
::
function
<
void
(
Args
...)
>
;
mutable
CallbackType
callback
=
NULL
;
public:
Callback
(){};
void
add
(
CallbackType
newCallback
)
const
{
if
(
callback
==
NULL
)
{
callback
=
newCallback
;
}
else
{
auto
oldCallback
=
callback
;
callback
=
[
newCallback
,
oldCallback
](
Args
&&
...
args
)
{
oldCallback
(
std
::
forward
<
Args
>
(
args
)...);
newCallback
(
std
::
forward
<
Args
>
(
args
)...);
};
}
}
void
operator
()(
Args
&&
...
args
)
const
{
if
(
callback
!=
NULL
)
{
callback
(
std
::
forward
<
Args
>
(
args
)...);
}
}
};
}
// namespace qthing
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment