0
点赞
收藏
分享

微信扫一扫

d用户以缓冲为成员类型


​​原文​​

struct S(T, size_t memberCapacity = size_t.max) {
static if (memberCapacity != size_t.max) {
// 用户想要成员数组
T[memberCapacity] arr;

void initMemberArray() {
// 初化...
}

} else {
void initMemberArray() {
// 这里,不用.
}
}

// ...
}

void main() {
auto a = S!int();
auto b = S!(int, 42)();

pragma(msg, a.sizeof); // 1
pragma(msg, b.sizeof); // 168
}

可用​​-profile=gc​​​跟踪​​GC​​分配.


举报

相关推荐

0 条评论