目前我正在为不同的调用约定(__stdcall,__ cdecl,__ fastcall等)构建仿函数(可调用类型).使用包装器,我将能够做到这样的事情:
void __stdcall foo(int arg)
{
std::printf("arg: %i\n", arg);
}
int main(int, char**)
{
Function<void, int> v{foo};
v(1337);
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
目前,我为__stdcall调用约定构建了一个包装器,只要指定了正确的参数并传入了正确的参数,就可以调用任何__stdcall函数.该类如下所示:
template <typename ReturnT, typename... Args>
class Function
{
// NOTE: This version of my callable types
// only supports the __stdcall calling
// convention. I need support for __cdecl,
// __fastcall and also __thiscall.
using return_t = ReturnT;
using callable_t = return_t(__stdcall*)(Args...);
private:
callable_t mCallable;
public:
template <typename FuncT>
Function(FuncT const &func) :
mCallable(func)
{
; …Run Code Online (Sandbox Code Playgroud) 在测试聚合类型时,我尝试使用boost :: proto :: is_aggregate来检查我正在创建的类型是否真正聚合.我写了这段代码:
#include <iostream>
#include <boost\proto\traits.hpp>
struct IsAggregate
{
IsAggregate &operator=(IsAggregate const &rhs) {}
};
int main()
{
std::cout << std::boolalpha;
std::cout << boost::proto::is_aggregate<IsAggregate>() << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我期望输出为真,因为聚合类型可以定义一个拷贝赋值运算符(根据这个:什么是聚合和POD以及它们如何/为什么特殊?)
但输出是错误的.
我还使用了上一个答案中的聚合类,它应该返回true但返回false.
这是使用英特尔编译器和MSVC在Boost 1.5.9上测试的.
有关为何发生这种情况的任何想法?