@@ -10,9 +10,10 @@ import { _IDeque } from "../base/container/IDequeContainer";
1010import { _IFront } from "../base/container/ILinearContainer" ;
1111import { _IListAlgorithm } from "../base/disposable/IListAlgorithm" ;
1212
13- import { ForOfAdaptor } from "../base/iterator/ForOfAdaptor" ;
1413import { _Repeater } from "../base/iterator/_Repeater" ;
14+ import { ForOfAdaptor } from "../base/iterator/ForOfAdaptor" ;
1515import { Vector } from "./Vector" ;
16+ import { OutOfRange } from "../exception/LogicError" ;
1617
1718import { advance , distance } from "../iterator/global" ;
1819import { equal_to , less } from "../functional/comparators" ;
@@ -37,17 +38,17 @@ export class ForwardList<T>
3738 /**
3839 * @hidden
3940 */
40- private size_ ! : number ;
41+ private size_ : number ;
4142
4243 /**
4344 * @hidden
4445 */
45- private before_begin_ ! : ForwardList . Iterator < T > ;
46+ private before_begin_ : ForwardList . Iterator < T > ;
4647
4748 /**
4849 * @hidden
4950 */
50- private end_ ! : ForwardList . Iterator < T > ;
51+ private end_ : ForwardList . Iterator < T > ;
5152
5253 /* ===============================================================
5354 CONSTRUCTORS & SEMI-CONSTRUCTORS
@@ -95,7 +96,9 @@ export class ForwardList<T>
9596 {
9697 this . ptr_ = { value : this } ;
9798
98- this . clear ( ) ;
99+ this . end_ = ForwardList . Iterator . create ( this . ptr_ , null ! ) ;
100+ this . before_begin_ = ForwardList . Iterator . create ( this . ptr_ , this . end_ ) ;
101+ this . size_ = 0 ;
99102
100103 if ( args . length === 1 && args [ 0 ] instanceof Array )
101104 {
@@ -136,7 +139,6 @@ export class ForwardList<T>
136139 public assign ( first : any , last : any ) : void
137140 {
138141 this . clear ( ) ;
139-
140142 this . insert_after ( this . before_begin_ , first , last ) ;
141143 }
142144
@@ -145,9 +147,7 @@ export class ForwardList<T>
145147 */
146148 public clear ( ) : void
147149 {
148- this . end_ = ForwardList . Iterator . create ( this . ptr_ , null ! , null ! ) ;
149- this . before_begin_ = ForwardList . Iterator . create ( this . ptr_ , this . end_ ) ;
150-
150+ ForwardList . Iterator . _Set_next ( this . before_begin_ , this . end_ ) ;
151151 this . size_ = 0 ;
152152 }
153153
@@ -607,6 +607,7 @@ export namespace ForwardList
607607 */
608608 public get value ( ) : T
609609 {
610+ this . _Try_value ( ) ;
610611 return this . value_ ! ;
611612 }
612613
@@ -615,9 +616,26 @@ export namespace ForwardList
615616 */
616617 public set value ( val : T )
617618 {
619+ this . _Try_value ( ) ;
618620 this . value_ = val ;
619621 }
620622
623+ /**
624+ * @hidden
625+ */
626+ private _Try_value ( ) : void
627+ {
628+ if ( this . value_ === undefined )
629+ {
630+ let source : ForwardList < T > = this . source ( ) ;
631+
632+ if ( this . equals ( source . end ( ) ) === true )
633+ throw new OutOfRange ( "Error on std.ForwardList.Iterator.value: cannot access to the std.ForwardList.end().value." ) ;
634+ else if ( this . equals ( source . before_begin ( ) ) === true )
635+ throw new OutOfRange ( "Error on std.ForwardList.Iterator.value: cannot access to the std.ForwardList.before_begin().value." ) ;
636+ }
637+ }
638+
621639 /* ---------------------------------------------------------
622640 MOVERS
623641 --------------------------------------------------------- */
0 commit comments