问题描述
是否可以像这样专门化 std::allocator_traits 模板?
namespace falloc_ {
template<class Tp> class FAllocator ;
}
// partial spec for all falloc_::FAllocator<U>,std::allocator_traits
template<typename Tp>
struct std::allocator_traits<falloc_::FAllocator<Tp> > {
using allocator_type = falloc_::FAllocator<Tp> ;
using value_type = typename allocator_type::value_type ;
// ...
// All the components I need here,I will include all the code if You need them.
// ...
} ;
namespace falloc_ {
template<class Tp> class FAllocator {
public:
using value_type = Tp ;
} ;
}
完整代码编译运行在std++20分配器类和分配器、特征类(std::allocator_traits)规范中。在那种情况下,我的问题实际上是关于实际的正确性,无论是根据对标准有更多了解的人,是否禁止类似的要素类重载,或者只是假设(完整的)代码是可编译和可执行的,并且根据预期计划 - 我可以考虑使用它吗?
另外,我用代码测试了分配器:
std::vector<int,falloc_::FAllocator<int> > mv ;
for (size_t i = 0 ; i < 5 ; i++) {
mv.push_back(i) ;
}
for (int i = 4 ; i > -1 ; i--) {
std::cout << "mv[" << i << "]: " << mv[i] << '\n' ;
}
内存已正确分配和释放,我还检查了 Valgrind。 使用 Gdb,我检查并从
调用了所有函数std::allocator_traits<falloc_::FAllocator<U> > // U aka int for std::vector<int,falloc_::FAllocator<int> >
预先感谢您提供任何见解、建议和意见。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)