能力值:
( LV12,RANK:380 )
|
-
-
2 楼
思路不错 还可以再优雅点...
|
能力值:
( LV2,RANK:15 )
|
-
-
3 楼
请Tennn老师发言
|
能力值:
( LV7,RANK:105 )
|
-
-
4 楼
调用约定也写成模版参数?
|
能力值:
( LV2,RANK:15 )
|
-
-
5 楼
看雪的引用现在又没用了?我是回复来着,结果没生效
|
能力值:
( LV2,RANK:15 )
|
-
-
6 楼
大佬们再补充点啊,
|
能力值:
( LV7,RANK:105 )
|
-
-
7 楼
mb_ldtiaylu
大佬们再补充点啊,
BlackBone里面的RemoteCall有类似的变参模板,但是在申明的时候还是得提供完整的函数类型,可以细细品一下,这里这种写法可以参数自动推导,省事一丢丢,具体看自己的使用场景去改造改造
|
能力值:
( LV2,RANK:10 )
|
-
-
8 楼
一般我是直接asm.学习了。
|
能力值:
( LV2,RANK:15 )
|
-
-
9 楼
最后于 2019-10-25 16:57
被mb_ldtiaylu编辑
,原因:
|
能力值:
( LV2,RANK:10 )
|
-
-
10 楼
vs2010 好像不支持 最低版本 2015 ???
|
能力值:
( LV2,RANK:10 )
|
-
-
11 楼
翻出来了就mark一下
|
能力值:
( LV2,RANK:10 )
|
-
-
12 楼
mark
|
能力值:
( LV6,RANK:80 )
|
-
-
13 楼
#pragma once
#include <type_traits>
namespace base {
namespace call_ {
template <class OutputClass, class InputClass>
struct same_size {
static const bool value =
(!std::is_reference_v<InputClass> && sizeof(OutputClass) == sizeof(InputClass))
|| (std::is_reference_v<InputClass> && sizeof(OutputClass) == sizeof(std::add_pointer_t<InputClass>));
};
template <class OutputClass, class InputClass>
union cast_union
{
OutputClass out;
InputClass in;
};
template <class Argument>
inline uintptr_t cast(const Argument input, std::enable_if_t<std::is_function_v<std::remove_reference_t<Argument>>, void>* = 0)
{
cast_union<uintptr_t, Argument> u;
static_assert(std::is_trivially_copyable_v<Argument>, "Argument is not a pod.");
static_assert((sizeof(Argument) == sizeof(u)) && (sizeof(Argument) == sizeof(uintptr_t)), "Argument and uintptr_t are not the same size.");
u.in = input;
return u.out;
}
template <class Argument>
inline uintptr_t cast(const Argument input, std::enable_if_t<!std::is_function_v<std::remove_reference_t<Argument>> && same_size<uintptr_t, Argument>::value, void>* = 0)
{
cast_union<uintptr_t, Argument> u{};
static_assert(std::is_trivially_copyable_v<Argument>, "Argument is not a pod.");
u.in = input;
return u.out;
}
template <class Argument>
inline uintptr_t cast(const Argument input, std::enable_if_t<!std::is_function_v<std::remove_reference_t<Argument>> && !same_size<uintptr_t, Argument>::value, void>* = 0)
{
static_assert(std::is_trivially_copyable_v<Argument>, "Argument is not a pod.");
static_assert(sizeof(Argument) < sizeof(uintptr_t), "Argument can not be converted to uintptr_t.");
return static_cast<uintptr_t>(input);
}
template <typename Arg>
struct cast_type {
typedef uintptr_t type;
};
}
template <typename R, typename F, typename ... Args>
inline R std_call(F f, Args ... args)
{
return (reinterpret_cast<R(__stdcall *)(typename call_::cast_type<Args>::type ... args)>(f))(call_::cast(args)...);
}
template <typename R, typename F, typename ... Args>
inline R fast_call(F f, Args ... args)
{
return (reinterpret_cast<R(__fastcall *)(typename call_::cast_type<Args>::type ... args)>(f))(call_::cast(args)...);
}
template <typename R, typename F, typename ... Args>
inline R c_call(F f, Args ... args)
{
return (reinterpret_cast<R(__cdecl *)(typename call_::cast_type<Args>::type ... args)>(f))(call_::cast(args)...);
}
template <typename R, typename F, typename This, typename ... Args>
inline R this_call(F f, This t, Args ... args)
{
return (reinterpret_cast<R(__fastcall *)(typename call_::cast_type<This>::type, void*, typename call_::cast_type<Args>::type ... args)>(f))(call_::cast(t), 0, call_::cast(args)...);
}
}
P.S: 需要C++20
最后于 2022-6-5 00:24
被黑洛编辑
,原因:
|
|
|