gpt4 book ai didi

c++ - C++标准库中有没有类似于没有成员的struct的类型?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:16:23 25 4
gpt4 key购买 nike

有时需要将没有任何数据的虚拟值传递给某些模板。例如:

template <typename X, typename Y> 
struct BoundaryConditions {
X x; Y y;
BoundaryConditions(typename X::init xi, typename Y::init yi) : x(xi), y(yi) {
...
}
};

我们可能希望实现不带任何参数的自由边界条件。通过类型检查实现这样的事情非常容易:

struct Nothing {};
Nothing nothing = Nothing();

struct Free {
typedef Nothing init;
...
};

BoundaryConditions<Free, Fixed> foo(nothing, 100);

所以我的问题是:在标准库或 boost 中是否有类似我的 Nothing 类型的实现?

最佳答案

您可以使用空的 tuple .喜欢std::tuple<>();

关于c++ - C++标准库中有没有类似于没有成员的struct的类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19448725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com