mirror of
https://github.com/Naios/continuable.git
synced 2026-02-09 03:06:41 +08:00
basic idea of callback containers
This commit is contained in:
parent
91891420cd
commit
60f1e04ea9
@ -49,7 +49,7 @@ namespace detail
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename _CTy>
|
template<typename _CTy>
|
||||||
using unwrap_callback = do_unwrap_callback<::fu::argument_type_t<_CTy>>;
|
using unwrap_callback = do_unwrap_callback<::fu::argument_type_of_t<_CTy>>;
|
||||||
|
|
||||||
} // detail
|
} // detail
|
||||||
|
|
||||||
@ -63,11 +63,11 @@ template<typename _CTy>
|
|||||||
using weak_callback_of_t = typename detail::unwrap_callback<_CTy>::WeakCallbackType;
|
using weak_callback_of_t = typename detail::unwrap_callback<_CTy>::WeakCallbackType;
|
||||||
|
|
||||||
template<typename _CTy>
|
template<typename _CTy>
|
||||||
typename shared_callback_of_t<_CTy>
|
inline typename shared_callback_of_t<_CTy>
|
||||||
make_shared_callback(_CTy&& callback)
|
make_shared_callback(_CTy&& callback)
|
||||||
{
|
{
|
||||||
return std::make_shared<typename callback_of_t<_CTy>>
|
return std::make_shared<typename callback_of_t<_CTy>>
|
||||||
(std::forward<typename callback_of_t<_CTy>>(callback));
|
(std::forward<typename callback_of_t<_CTy>>(callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /// _TASK_SCHEDULER_H_
|
#endif /// _CALLBACK_H_
|
||||||
|
|||||||
39
fluent++/CallbackContainer.h
Normal file
39
fluent++/CallbackContainer.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _CALLBACK_CONTAINER_H_
|
||||||
|
#define _CALLBACK_CONTAINER_H_
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include "Callback.h"
|
||||||
|
|
||||||
|
class CallbackContainer
|
||||||
|
{
|
||||||
|
size_t current_handle;
|
||||||
|
|
||||||
|
std::unordered_map<decltype(current_handle), void*> container;
|
||||||
|
|
||||||
|
public:
|
||||||
|
template<typename _CTy>
|
||||||
|
_CTy operator()(_CTy&& callback)
|
||||||
|
{
|
||||||
|
return callback;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /// _CALLBACK_CONTAINER_H_
|
||||||
@ -114,22 +114,22 @@ namespace fu
|
|||||||
|
|
||||||
/// Trait which defines the return type of the function.
|
/// Trait which defines the return type of the function.
|
||||||
template<typename... Function>
|
template<typename... Function>
|
||||||
using return_type_t =
|
using return_type_of_t =
|
||||||
typename detail::select_best_unwrap<Function...>::type::return_type;
|
typename detail::select_best_unwrap<Function...>::type::return_type;
|
||||||
|
|
||||||
/// Trait which defines the argument types of the function packed in std::tuple.
|
/// Trait which defines the argument types of the function packed in std::tuple.
|
||||||
template<typename... Function>
|
template<typename... Function>
|
||||||
using argument_type_t =
|
using argument_type_of_t =
|
||||||
typename detail::select_best_unwrap<Function...>::type::argument_type;
|
typename detail::select_best_unwrap<Function...>::type::argument_type;
|
||||||
|
|
||||||
/// Trait which defines the std::function type of the function.
|
/// Trait which defines the std::function type of the function.
|
||||||
template<typename... Function>
|
template<typename... Function>
|
||||||
using function_type_t =
|
using function_type_of_t =
|
||||||
typename detail::select_best_unwrap<Function...>::type::function_type;
|
typename detail::select_best_unwrap<Function...>::type::function_type;
|
||||||
|
|
||||||
/// Trait which defines the function pointer type of the function.
|
/// Trait which defines the function pointer type of the function.
|
||||||
template<typename... Function>
|
template<typename... Function>
|
||||||
using function_ptr_t =
|
using function_ptr_of_t =
|
||||||
typename detail::select_best_unwrap<Function...>::type::function_ptr;
|
typename detail::select_best_unwrap<Function...>::type::function_ptr;
|
||||||
|
|
||||||
} // fu
|
} // fu
|
||||||
|
|||||||
7
test.cpp
7
test.cpp
@ -2,6 +2,7 @@
|
|||||||
#include "fluent++.hpp"
|
#include "fluent++.hpp"
|
||||||
|
|
||||||
#include "Callback.h"
|
#include "Callback.h"
|
||||||
|
#include "CallbackContainer.h"
|
||||||
|
|
||||||
void CastSpell(int id, Callback<bool> const& callback)
|
void CastSpell(int id, Callback<bool> const& callback)
|
||||||
{
|
{
|
||||||
@ -50,5 +51,11 @@ int main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
});
|
});
|
||||||
|
|
||||||
|
CallbackContainer callback;
|
||||||
|
|
||||||
|
auto mycb = callback([]
|
||||||
|
{
|
||||||
|
});
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user