-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
BackInsertIterator.ts
64 lines (59 loc) · 1.7 KB
/
BackInsertIterator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//================================================================
/**
* @packageDocumentation
* @module std
*/
//================================================================
import { InsertIteratorBase } from "../internal/iterator/InsertIteratorBase";
;
import { IPushBack } from "../internal/container/partial/IPushBack";
import { Vector } from "../container/Vector";
import { equal_to } from "../functional/comparators";
/**
* Back insert iterator.
*
* @author Jeongho Nam - https://github.com/samchon
*/
export class BackInsertIterator<Source extends IPushBack<BackInsertIterator.ValueType<Source>>>
extends InsertIteratorBase<BackInsertIterator.ValueType<Source>, BackInsertIterator<Source>>
{
private source_: Source;
/* ---------------------------------------------------------
METHODS
--------------------------------------------------------- */
/**
* Initializer Constructor.
*
* @param source The source container.
*/
public constructor(source: Source)
{
super();
this.source_ = source;
}
/**
* @inheritDoc
*/
public set value(val: BackInsertIterator.ValueType<Source>)
{
this.source_.push_back(val);
}
/**
* @inheritDoc
*/
public equals(obj: BackInsertIterator<Source>): boolean
{
return equal_to(this.source_, obj.source_);
}
}
export namespace BackInsertIterator
{
export type ValueType<Source extends IPushBack<any>> =
Source extends IPushBack<infer T>
? T
: unknown;
export type SourceType<Source extends Array<any> | IPushBack<any>> =
Source extends Array<infer T>
? Vector<T>
: Source;
}