我创建了一个集合,我想提供一个STL风格的随机访问迭代器.我正在寻找迭代器的示例实现,但我没有找到任何.我知道需要const重载[]和*运算符.迭代器有什么要求是"STL风格",还有哪些其他缺陷需要避免(如果有的话)?
附加上下文:这是一个库,除非我真的需要,否则我不想引入任何依赖.我编写自己的集合,以便能够使用相同的编译器在C++ 03和C++ 11之间提供二进制兼容性(因此没有STL可能会破坏).
显然;-)标准容器提供某种形式的保证.
什么类型的保证以及不同类型的容器之间究竟有什么区别?
Container Types:
================
Container:
Forward Container
Reverse Container
Random Access Container
Sequence
Front Insert Sequence
Back Insert Sequence
Associative Container
Simple Associative Container
Pair Associative Container
Sorted Associative Container
Multiple Associative Container
Container Types mapped to Standard Containers
=============================================
std::vector: Sequence Back Sequence Forward/Reverse/Random Container
std::deque: Sequence Front/Back Sequence Forward/Reverse/Random Container
std::list: Sequence Front/Back Sequence Forward/Reverse Container
std::set: Sorted/Simple/Unique Associative Container Forward Container
std::map: Sorted/Pair/Unique Associative Container Forward Container
std::multiset: Sorted/Simple/Multiple Associative Container …Run Code Online (Sandbox Code Playgroud) 我是编程的新手,只是遇到了这个任务
创建一个包含20个人对象数组的容器类系列.
我一直在网上和我的书中看,但我仍然无法弄清楚容器类和C++中的类之间的区别.
我怎么能同时创建一个家庭类和20个人对象?
我有一个用C编写的.inc文件.它包含一些带有实现的定义和方法签名.
.inc文件:
#define CONCAT(x,y) x ## y
#define LCONCAT(x,y) CONCAT(x,y)
#define DLIST LCONCAT(LCONCAT(double_,LISTELEMENT),_list)
#define DELETEDFIRST LCONCAT(delete_first_double_,LISTELEMENT)
int DELETEDFIRST (DLIST **first, DLIST **last);
int DELETEDFIRST (DLIST **first, DLIST **last)
{...}
Run Code Online (Sandbox Code Playgroud)
我想把它带到c ++.在我的.h文件中,我有define指令和方法签名(封装在命名空间中).在.cpp我只有方法实现.
.h文件
#define CONCAT(x,y) x ## y
#define LCONCAT(x,y) CONCAT(x,y)
#define DLIST LCONCAT(LCONCAT(double_,LISTELEMENT),_list)
#define DELETEDFIRST LCONCAT(delete_first_double_,LISTELEMENT)
namespace ListFunctions {
int DELETEDFIRST (DLIST **first, DLIST **last);
}
Run Code Online (Sandbox Code Playgroud)
.cpp文件
# include ListFunctions.h
namespace ListFunctions {
int DELETEDFIRST (DLIST **first, DLIST **last) {...}
}
Run Code Online (Sandbox Code Playgroud)
我打算在开发我的模块时使用这些列表函数.在我的module.h中,我定义了一个类型double_ node _list(双端),在我的module.cpp中,我将LISTELEMENT定义为" node ",然后包含ListFunctions.h.但ListFunctions.cpp中的相同内容会导致编译错误:
..\ListFunctions.h(86): error …Run Code Online (Sandbox Code Playgroud)