最近我一直在使用放大器(C ++ Accelerated Massive Parallelism)。使用此框架需要大量带有restrict(amp)
的lambda表达式。但是,当我尝试在模板类中编写这些时,编译器会抛出Error C2760 syntax error: unexpected token 'identifier', expected '{'
的错误消息。但是,它在没有restricted(amp)
或模板类之外的情况下工作得很好。以下是可以重现此类问题的代码:
//matrix2.cpp
#pragma once
#include "stdafx.h"
namespace rin
{
template <int V0, int V1>
class Matrix2
{
public:
Matrix2() : raw_(V0 * V1), view_(concurrency::extent<2>(V0, V1), raw_)
{
concurrency::parallel_for_each(concurrency::extent<2>(V0, V1),
[=](concurrency::index<2> idx)
restrict(amp)
{
});
auto fun = [=]() restrict(cpu)
{
std::cout << "It does not compile in a template class." << std::endl;
};
fun();
auto fun1 = [=]()
{
std::cout << "It does compile in a template class without the restrict(...)." << std::endl;
};
fun1();
}
std::vector<double> raw_;
concurrency::array_view<double, 2> view_;
};
}
//main.cpp
#include "stdafx.h"
#include "matrix.h"
using namespace rin;
using namespace concurrency;
int main()
{
Matrix2<5, 5> mat;
auto fun = [=]() restrict(cpu)
{
std::cout << "But outside the template class it does work!" << std::endl;
};
fun();
system("pause");
return 0;
}