我创建了一个静态断言,以确保我不会调用创建唯一指针的辅助函数(它是我的内存调试代码的一部分)。
我面临的问题是断言似乎在 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/