在没有函数调用的情况下确定 std::array return 类型的大小

Determine size of std::array return type without a function call

我有一个 class B 将 class 像 A 作为模板参数。

template<typename T>
class B{
///...

每个 T 都有一个 operator()(),returns 有一个 std::array<double, N>。我希望每个特化 B<T> 都能够推导出 N 而无需对 T 提出额外要求并且无需调用 operator()()。我该怎么做?

下面是一个示例 T,标记为 class A:

template <int N>
class A {
public:
    A() {}

    std::array<double, N> operator()() {
        std::array<double, N> the_integers;
        for (int i = 0; i < N; ++i) {
            the_integers[i] = i;
        }
        return the_integers;
    }
};

您可以像这样向 B 添加成员

static constexpr std::size_t ArraySize = std::tuple_size_v<decltype(std::declval<T&>()())>;

这是一个demo