小编אנו*_*ימי的帖子

在没有 C++ 实例的情况下获取 unique_ptr 内 std::array 的大小

我有一个类型声明为:

using Buffer = std::unique_ptr<std::array<uint8_t, N>>;
Run Code Online (Sandbox Code Playgroud)

我还有一个模板函数声明为:

template<typename Buffer>
bool temp_func()
{
    // do something
}
Run Code Online (Sandbox Code Playgroud)

我正在使用 Buffer 类型调用 temp_func:

temp_func<Buffer>();
Run Code Online (Sandbox Code Playgroud)

现在,在 temp_func 中,我想获取该类型的大小Buffer,而不创建该类型的实例。

我需要的是类似于std::tuple_size<Buffer>::value除了我不能调用std::tuple_sizeunique_ptr只能直接调用std::array

我只能使用 C++11。我该怎么做?

c++ unique-ptr c++11 stdarray

5
推荐指数
1
解决办法
205
查看次数

标签 统计

c++ ×1

c++11 ×1

stdarray ×1

unique-ptr ×1