mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-29 22:04:02 -06:00
New Core Tutorial
git-svn-id: svn://ultimatepp.org/upp/trunk@10538 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
dd88feaf2e
commit
6c22e727de
37 changed files with 3125 additions and 0 deletions
54
tutorial/CoreTutorial/Bidirectional.cpp
Normal file
54
tutorial/CoreTutorial/Bidirectional.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#include "Tutorial.h"
|
||||
|
||||
void Bidirectional()
|
||||
{
|
||||
/// .Bidirectional containers
|
||||
|
||||
/// `Vector` and `Array` containers allow fast adding and removing elements at the end of
|
||||
/// sequence. Sometimes, same is needed at begin of sequence too (usually to support FIFO
|
||||
/// queues). `BiVector` and `BiArray` are optimal for this scenario:
|
||||
|
||||
BiVector<int> n;
|
||||
n.AddHead(1);
|
||||
n.AddTail(2);
|
||||
n.AddHead(3);
|
||||
n.AddTail(4);
|
||||
DUMP(n);
|
||||
|
||||
///
|
||||
|
||||
n.DropHead();
|
||||
DUMP(n);
|
||||
|
||||
///
|
||||
|
||||
n.DropTail();
|
||||
DUMP(n);
|
||||
|
||||
///
|
||||
|
||||
struct Val {
|
||||
virtual String ToString() const = 0;
|
||||
virtual ~Val() {}
|
||||
};
|
||||
|
||||
struct Number : Val {
|
||||
int n;
|
||||
virtual String ToString() const { return AsString(n); }
|
||||
};
|
||||
|
||||
struct Text : Val {
|
||||
String s;
|
||||
virtual String ToString() const { return s; }
|
||||
};
|
||||
|
||||
BiArray<Val> num;
|
||||
num.CreateHead<Number>().n = 3;
|
||||
num.CreateTail<Text>().s = "Hello";
|
||||
num.CreateHead<Text>().s = "World";
|
||||
num.CreateTail<Number>().n = 2;
|
||||
|
||||
DUMP(num);
|
||||
|
||||
///
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue