S. *_* O. 5 c++ visual-studio visual-c++ c++17
我试图创建一组具有不同操作的策略类,这些操作实现为静态成员lambdas.这样我就可以根据给定的策略在相同操作的不同版本之间进行选择,并将操作传递给某些算法,例如std :: transform.
这引导我使用CRTP进行以下设计,其中基类实现了lambda.请注意,C++ 17允许定义constexpr lambdas.
namespace test
{
template <class B>
struct A
{
// The same thing happens if this is static const instead
static constexpr auto t = [](const auto c) {};
};
struct C : A<C>
{};
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它时,我得到了错误
错误C2888:'auto :: operator()(_ T1)const':符号无法在命名空间'test'中定义
错误C2888:'auto ::(_ T1)':无法在命名空间'test'中定义符号
错误C2888: '::操作者未知类型(__cdecl*)(_ T1)(__ CDECL*(无效)noexcept常数)(_ T1)':符号不能命名空间 '测试' 中定义
...
对于一些不同的调用约定,后面跟着相同的错误.但是,没有周围命名空间的以下代码编译得很好.
template <class B>
struct A
{
static constexpr auto t = [](const auto c) {};
};
struct C : A<C>
{};
Run Code Online (Sandbox Code Playgroud)
我已经检查过,第一个版本在gcc 8.2和clang 7上用std = c ++ 17编译.我在这里遗漏了什么或这是一个错误吗?我正在使用Visual Studio 15.9.4的社区版.
提前致谢.
编辑:似乎你只能使用一个带有静态constexpr泛型lambda的简单类来重现这个问题.这无法编译:
namespace test
{
struct A
{
static constexpr auto t = [](auto c) {};
};
}
Run Code Online (Sandbox Code Playgroud)
但这编译得很好.
struct A
{
static constexpr auto t = [](auto c) {};
};
Run Code Online (Sandbox Code Playgroud)
最后,如果lambda不是通用的,则第一个版本可以工作.
namespace test
{
struct A
{
static constexpr auto t = [](char c) {};
};
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
122 次 |
| 最近记录: |