阿尔卑斯构建环境中的 C++ 模板
c++ templates in alpine build environments
我不知为什么这样的非类型模板参数构造
template <typename TValue, typename TFile, size_t PAGESIZE>
inline typename Size<Buffer<TValue, PageFrame<TFile, Fixed<PAGESIZE> > > >::Type
capacity(Buffer<TValue, PageFrame<TFile, Fixed<PAGESIZE> > > const &)
{
return PAGESIZE;
}
会用Alpines buildbase/gcc/stdlibc++/cmake软件包绊倒clang(4.0.0(和g++(6.3.0(。这发生在阿尔卑斯山:
file_page.h:76:22: error: expected ',' or '>' in template-parameter-list
template <size_t PAGESIZE>
^
/usr/include/limits.h:44:18: note: expanded from macro 'PAGESIZE'
#define PAGESIZE PAGE_SIZE
^
/usr/include/bits/limits.h:3:19: note: expanded from macro 'PAGE_SIZE'
#define PAGE_SIZE 4096
^
在我看来,宏观扩张在这里非常有意。任何解释都值得赞赏
精简后,您的代码类似于以下内容:
#include <cstddef>
#define PAGE_SIZE 4096
#define PAGESIZE PAGE_SIZE
template<std::size_t PAGESIZE>
void f() {}
您正在使用与扩展到特定值的宏相同的名称来命名非类型模板参数。就好像你写了:
#include <cstddef>
template<std::size_t 4096>
void f() {}
这显然是无效的语法。
如果要将非类型模板参数的默认值设置为宏的值,可以这样编写:
#include <cstddef>
#define PAGE_SIZE 4096
#define PAGESIZE PAGE_SIZE
template<std::size_t page_size = PAGESIZE>
void f() {}
但是,请确保在函数中使用page_size
而不是PAGESIZE
宏。
相关文章:
- .cpp和.h文件中的模板专用化声明
- C++模板来检查友元函数的存在
- 如何使用默认参数等选择模板专业化
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- 部分定义/别名模板模板参数
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 如何在c++中为模板函数实例创建快捷方式
- 使用C++中的模板和运算符重载执行矩阵运算
- 有人能分解一下这个c++模板的语法吗
- 如何在c++17中制作一个模板包装器/装饰器
- 模板化建造师专业化
- 调用专用模板时出错"no matching function for call to [...]"
- 模板元程序查找相似的连续类型名称
- 如何在C++20中创建模板别名的推导指南
- 没有名称的C++模板参数
- 具有重复类型的C++可变模板
- 如何将enable-if与模板参数和参数包一起使用
- 没有用于初始化C++中的变量模板的匹配构造函数