0

我有一个带有两个非类型模板参数的 C++ 类:

size_t 类型的维度和对对象向量的 const 引用。

template <size_t DIMENSION, const std::vector<Tuple>& BORDERS>
class Rule {
public:

  Rule(const std::vector<Tuple>& ranges, const Action& action) :
      ranges_(ranges),
      action_(action) {};

private:

  std::vector<Tuple> ranges_;
  Action action_;
};

是否有可能在编译时确保以下条件成立?

DIMENSION == BORDERS.size()

提前感谢您的任何建议。

4

1 回答 1

1

A vector is a dynamic container, so its size depends on how you use it at run-time. Unfortunately that means there is no compile-time check you can do to achieve what you want.

std::array may be more suitable in this case, as its size is fixed at compile time.

于 2013-11-07T14:00:36.670 回答