c – 标准库中的空类型

前端之家收集整理的这篇文章主要介绍了c – 标准库中的空类型前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有时需要将空类型传递给某个模板.例如:
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);

所以我的问题是:在标准库或者提升中是否有类似我的“Nothing”类型的实现?

解决方法

你可以使用空 tuple.像std :: tuple<>();
原文链接:https://www.f2er.com/c/111290.html

猜你在找的C&C++相关文章