basic idea of callback containers

This commit is contained in:
Naios 2015-06-10 00:07:51 +02:00
parent 91891420cd
commit 60f1e04ea9
4 changed files with 53 additions and 7 deletions

View File

@ -49,7 +49,7 @@ namespace detail
};
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
@ -63,11 +63,11 @@ template<typename _CTy>
using weak_callback_of_t = typename detail::unwrap_callback<_CTy>::WeakCallbackType;
template<typename _CTy>
typename shared_callback_of_t<_CTy>
inline typename shared_callback_of_t<_CTy>
make_shared_callback(_CTy&& callback)
{
return std::make_shared<typename callback_of_t<_CTy>>
(std::forward<typename callback_of_t<_CTy>>(callback));
}
#endif /// _TASK_SCHEDULER_H_
#endif /// _CALLBACK_H_

View 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_

View File

@ -114,22 +114,22 @@ namespace fu
/// Trait which defines the return type of the function.
template<typename... Function>
using return_type_t =
using return_type_of_t =
typename detail::select_best_unwrap<Function...>::type::return_type;
/// Trait which defines the argument types of the function packed in std::tuple.
template<typename... Function>
using argument_type_t =
using argument_type_of_t =
typename detail::select_best_unwrap<Function...>::type::argument_type;
/// Trait which defines the std::function type of the function.
template<typename... Function>
using function_type_t =
using function_type_of_t =
typename detail::select_best_unwrap<Function...>::type::function_type;
/// Trait which defines the function pointer type of the function.
template<typename... Function>
using function_ptr_t =
using function_ptr_of_t =
typename detail::select_best_unwrap<Function...>::type::function_ptr;
} // fu

View File

@ -2,6 +2,7 @@
#include "fluent++.hpp"
#include "Callback.h"
#include "CallbackContainer.h"
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;
}