C++自定义分配器和STL容器
C++ custom allocators and STL containers
我一直在尝试使用带有basic_string和STL容器的自定义SecureAllocater,但运气很差。
typedef std::basic_string< char, std::char_traits< char >, SecureAllocator< char > > SecureString;
SecureString value = "hello, world!";
vector< SecureString > collection;
collection.push_back( value );
In file included from /Users/bcrowhurst/source/utility/string_impl.cpp:31:
In file included from /Users/bcrowhurst/build/../source/utility/string_impl.h:31:
/usr/bin/../lib/c++/v1/string:2162:19: error: invalid operands to binary expression ('allocator_type' (aka 'SecureAllocator<char>') and 'allocator_type')
if (__alloc() != __str.__alloc())
~~~~~~~~~ ^ ~~~~~~~~~~~~~~~
环境
Mac OSX Lion
Apple clang 3.1版(标签/Apple/crang-318.0.61)(基于LLVM 3.1svn)
目标:x86_64-apple-darwin11.4.0
线程模型:posix
您必须为分配器类型实现比较运算符,判断它们是否"等价",以便可以互换(或不互换)使用。
比较两个分配器a1 == a2
的要求是
仅当从每个分配的存储可以通过另一个释放时,返回true。
operator==
应是自反的、对称的和传递的,并且不应通过异常退出。
对于a1 != a2
与
!(a1 == a2)
相同
相关文章:
- 在STL容器中使用模板类
- 检查函数返回类型是否与STL容器类型值相同
- 为什么 STL 容器适配器堆栈中的 top 返回常量引用?
- 如果我真的真的想从 STL 容器继承,并且我继承构造函数并删除新运算符,会发生什么?
- 对象 C++ 向量的 STL 容器
- 如何在不破坏现有应用程序的情况下更改 API 中 stl 容器的数据类型?
- 在 STL 容器的 STL 容器上调用 clear
- "迭代器"和"const_iterator"不是 STL 容器的必需成员?
- 删除包含包含动态对象的 STL 容器的智能指针
- C++:在子类中扩展静态 STL 容器/映射成员?
- ostream 运算符<< 为获取 STL 容器而过载,传递 std::string 会破坏它?
- 没有 STL 容器的迭代器
- 为什么某些 STL 容器(堆栈、队列、优先级队列)不支持迭代器?
- 接受任何 STL 容器的函数
- C++ STL 容器中优先级搜索的优雅方法
- 我们如何打印出C++ STL 容器的value_type?
- 获取嵌套 stl 容器的大小(以字节为单位)
- 如何在C++中重新实现包含指针的 STL 容器的类的迭代器
- 迭代器和 STL 容器的关系
- 如何用索引增量generate_n填充STL容器