【发布时间】:2018-03-27 14:46:33
【问题描述】:
我正在尝试创建某种比较函数,它将编译时已知的某些前缀与其他缓冲区进行比较。
我正在尝试使用预定义的std::arrays,它将前缀作为模板参数。
这是我尝试过的:
constexpr std::array<std::uint8_t, 4> ARRAY_A {{0xDE, 0xAD, 0xBE, 0xEF}};
constexpr std::array<std::uint8_t, 4> ARRAY_B {{0xBA, 0xD, 0xF0, 0x0D}};
enum class Foo{
A,B
};
template<size_t SizeOfHeader, std::array<std::uint8_t, SizeOfHeader> Header, Foo f>
void foo()
{
std::cout << __PRETTY_FUNCTION__ << std::endl;
}
template<template<class, class> class TContainer, Foo f>
void foo2()
{
std::cout << __PRETTY_FUNCTION__ << std::endl;
}
int main()
{
foo2<ARRAY_A, Foo::A>();
foo<ARRAY_A.size(), ARRAY_A, Foo::A>();
return 0;
}
我有兴趣了解代码中的错误,就像找到一个可行的解决方案一样 :)
Here 是对 coliru 的失败尝试。错误是:
main.cpp:31:5: error: no matching function for call to 'foo2'
foo2<ARRAY_A, Foo::A>();
^~~~~~~~~~~~~~~~~~~~~
main.cpp:23:6: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'TContainer'
void foo2()
^
main.cpp:32:5: error: no matching function for call to 'foo'
foo<ARRAY_A.size(), ARRAY_A, Foo::A>();
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:17:6: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'Header'
void foo()
^
2 errors generated.
【问题讨论】:
-
@Quentin 包含完整错误和演示链接
-
完美! ------