繁体   English   中英

C ++自定义分配器和STL容器

[英]C++ custom allocators and STL containers

我一直在尝试使用带有basic_string和STL容器的自定义SecureAllocator,但我的运气很少。

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())
            ~~~~~~~~~ ^  ~~~~~~~~~~~~~~~

Envirnoment

Mac OSX Lion

Apple clang 3.1版(标签/ Apple / clang-318.0.61)(基于LLVM 3.1svn)

目标:x86_64-apple-darwin11.4.0

线程模型:posix

您必须为分配器类型实现比较运算符,告诉它们是否“等效”,以便它们可以互换(或不互换)。

比较两个分配器a1 == a2

仅当从每个分配的存储可以通过另一个分配时,才返回true。 operator==应具有自反性,对称性和传递性,不得通过异常退出。

并为a1 != a2

!(a1 == a2)相同!(a1 == a2)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM