gpt4 book ai didi

c++ - std::is_array 在应该返回 false 时返回 true?

转载 作者:行者123 更新时间:2023-11-28 04:47:17 25 4
gpt4 key购买 nike

我创建了一个静态断言,以确保我不会调用创建唯一指针的辅助函数(它是我的内存调试代码的一部分)。

我面临的问题是断言似乎在 T 时消失了。不是数组。

函数:

template<class T> n::c_uptr<T> mem::make_unique() {
static_assert(std::is_array_v<T>, "T must not be an array.");

return n::c_uptr<T>(nullptr, [](T * pv_object) { });
}

函数调用:

private: a_row_uptr iv_row = n::mem::make_unique<a_row>();

a_row是一个抽象类,我也试过 !std::is_abstract_v<T> && std::is_array_v<T> .

3>class_method_definitions\mem.h(122): error C2338: T must not be an array.
3>class_definitions\db\a_result.h(6): note: see reference to function template instantiation 'std::unique_ptr<n::db::a_row,std::function<void (_Ty *)>> n::mem::make_unique<n::db::a_row>(void)' being compiled
3> with
3> [
3> _Ty=n::db::a_row
3> ]

最佳答案

显然我需要反转条件语句,因为它会在评估为假而不是真时触发错误。

关于c++ - std::is_array 在应该返回 false 时返回 true?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49034732/

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