diff --git a/uppsrc/Core/Index.h b/uppsrc/Core/Index.h index 43e2e109b..3d6113999 100644 --- a/uppsrc/Core/Index.h +++ b/uppsrc/Core/Index.h @@ -97,9 +97,10 @@ public: T& Add(const T& x, unsigned _hash); T& Add(const T& x); + Index& operator<<(const T& x) { Add(x); return *this; } + int FindAdd(const T& key, unsigned _hash); int FindAdd(const T& key); - Index& operator<<(const T& x) { Add(x); return *this; } int Put(const T& x, unsigned _hash); int Put(const T& x); diff --git a/uppsrc/Core/Range.h b/uppsrc/Core/Range.h index 1a2d25190..8b6eb6389 100644 --- a/uppsrc/Core/Range.h +++ b/uppsrc/Core/Range.h @@ -1,3 +1,12 @@ +template +using ValueTypeOf = typename std::remove_referencebegin())>::type; + +template +using IteratorOf = decltype(((Range *)0)->begin()); + +template +using ConstIteratorOf = decltype(((const Range *)0)->begin()); + template class SubRangeClass { I l; diff --git a/uppsrc/Core/Sort.h b/uppsrc/Core/Sort.h index 25be5bd0e..15d140116 100644 --- a/uppsrc/Core/Sort.h +++ b/uppsrc/Core/Sort.h @@ -47,7 +47,7 @@ void FinalSort__(T& c, const Less& less) template void FinalSort__(T& c) { - typedef typename T::ValueType VT; + typedef ValueTypeOf VT; FinalSort__(c.begin(), c.end(), std::less()); } diff --git a/uppsrc/Core/Topt.h b/uppsrc/Core/Topt.h index fd9ae1bae..d1e90bb82 100644 --- a/uppsrc/Core/Topt.h +++ b/uppsrc/Core/Topt.h @@ -347,18 +347,9 @@ public: void pop_back() { Drop(); } \ -template -using ValueTypeOf = typename std::remove_referencebegin())>::type; - template using ValueTypeOfArray = typename std::remove_reference::type; -template -using IteratorOf = decltype(((Range *)0)->begin()); - -template -using ConstIteratorOf = decltype(((const Range *)0)->begin()); - template class ConstIIterator { typedef ValueTypeOfArray T; diff --git a/uppsrc/Core/src.tpp/AIndex$en-us.tpp b/uppsrc/Core/src.tpp/AIndex$en-us.tpp index 78e417bae..f1bdc9d9f 100644 --- a/uppsrc/Core/src.tpp/AIndex$en-us.tpp +++ b/uppsrc/Core/src.tpp/AIndex$en-us.tpp @@ -130,6 +130,11 @@ the element.&] [s6; Invalidates references to Index.&] [s3;%- &] [s4;%- &] +[s5;:Upp`:`:Index`:`:operator`<`<`(const T`&`):%- [_^Upp`:`:Index^ Index][@(0.0.255) `&]_ +[* operator<<]([@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 x])&] +[s2; Same as Add([%-*@3 x]).&] +[s3;%- &] +[s4;%- &] [s5;:Index`:`:Find`(const T`&`,unsigned`)const:%- [@(0.0.255) int]_[* Find]([@(0.0.255) con st]_[*@4 T][@(0.0.255) `&]_[*@3 x], [@(0.0.255) unsigned]_[*@3 `_hash])_[@(0.0.255) const]&] [s2; Returns the position of the first element with value [%-*@3 x] @@ -220,7 +225,7 @@ Unlinked elements are ignored.&] [s0;l288;a4;%- [*@5;1 Requires T to have deep copy constructor.]&] [s0;l288;a4;%- [*@5;1 Invalidates iterators to AIndex.]&] [s2;%- [*@5;1 Invalidates references to Index.]&] -[s3;%- &] +[s3; &] [s4;%- &] [s5;:Index`:`:Unlink`(int`):%- [@(0.0.255) void]_[* Unlink]([@(0.0.255) int]_[*@3 i])&] [s2; Unlinks the element at [%-*@3 i]. The unlinked item stays in AIndex diff --git a/uppsrc/Core/src.tpp/Range$en-us.tpp b/uppsrc/Core/src.tpp/Range$en-us.tpp index ec1014785..2fd8e9828 100644 --- a/uppsrc/Core/src.tpp/Range$en-us.tpp +++ b/uppsrc/Core/src.tpp/Range$en-us.tpp @@ -1,4 +1,4 @@ -topic ""; +topic "Range"; [2 $$0,0#00000000000000000000000000000000:Default] [i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class] [l288;2 $$2,2#27521748481378242620020725143825:desc] @@ -10,16 +10,91 @@ topic ""; [i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam] [b42;2 $$9,9#13035079074754324216151401829390:normal] [{_}%EN-US -[ {{10000@(113.42.0) [s0; [*@7;4 Title]]}}&] +[ {{10000@(113.42.0) [s0; [*@7;4 Range]]}}&] [s1;O_; &] -[s0; Range is a concept&] -[s1;:noref: [@(0.0.255)3 template][3 _<][@(0.0.255)3 class][3 _][*@4;3 I][3 >]&] -[s1;:Upp`:`:SubRangeClass`:`:class: [@(0.0.255) class]_[* SubRangeClass]&] -[s2; &] -[s3; &] -[s0;i448;a25;kKO9;@(0.0.255) &] -[ {{10000F(128)G(128)@1 [s0; [* Function List]]}}&] -[s0;i448;a25;kKO9;:noref:@(0.0.255) &] -[ {{10000F(128)G(128)@1 [s0; [* Public Method List]]}}&] +[s0; U`+`+ algorithms are designed to work on [*/ Ranges]. Range is +a type that has (at minimum)&] [s0; &] -[ {{10000F(128)G(128)@1 [s0; [* Constructor detail]]}}]] \ No newline at end of file +[s0;i150;O0; Standard begin() / end() methods.&] +[s0;i150;O0; GetCount() that returns the number of elements in Range +(can be implemented as end `- begin)&] +[s0;i150;O0; operator`[`] (can be implemented as begin()`[i`])&] +[s0; &] +[s0; Standard Ranges usually also implement ToString and comparisons +(if it is possible).&] +[s0; &] +[s0; Usually, Range is either U`+`+ container or just some part of +it.&] +[s0; &] +[s0; U`+`+ provides these Range related typedefs and template functions:&] +[s3; &] +[s4;%- &] +[s5;:Upp`:`:ValueTypeOf`:`:typedef:%- [@(0.0.255) template + using]_[* ValueTypeOf];&] +[s2; Returns the type of elements of Range.&] +[s3;%- &] +[s4;%- &] +[s5;:Upp`:`:IteratorOf`:`:typedef:%- [@(0.0.255) template +using]_[* IteratorOf];&] +[s5;:Upp`:`:ConstIteratorOf`:`:typedef:%- [@(0.0.255) template using]_[* ConstIteratorOf]`'&] +[s2; Returns the type of Iterator / ConstIterator of range.&] +[s3; &] +[s4;%- &] +[s5;:Upp`:`:SubRange`(I`,I`):%- [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 I]>_&] +[s5;:Upp`:`:SubRange`(I`,I`):%- [_^Upp`:`:SubRangeClass^ SubRangeClass]<[*@4 I]>_[* SubRang +e]([*@4 I]_[*@3 begin], [*@4 I]_[*@3 end])&] +[s2; Makes a Range based on begin/end iterators.&] +[s3; &] +[s4;%- &] +[s5;:Upp`:`:SubRange`(I`,int`):%- [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 I]>_&] +[s5;:Upp`:`:SubRange`(I`,int`):%- [_^Upp`:`:SubRangeClass^ SubRangeClass]<[*@4 I]>_[* SubRa +nge]([*@4 I]_[*@3 begin], [@(0.0.255) int]_[*@3 count])&] +[s2; Makes a Range based on begin iterator and count.&] +[s3; &] +[s4;%- &] +[s5;:Upp`:`:SubRange`(C`&`,int`,int`):%- [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 C]> +_&] +[s5;:Upp`:`:SubRange`(C`&`,int`,int`):%- [@(0.0.255) auto]_[* SubRange]([*@4 C][@(0.0.255) `& +]_[*@3 c], [@(0.0.255) int]_[*@3 pos], [@(0.0.255) int]_[*@3 count]);&] +[s5;:Upp`:`:SubRange`(const C`&`,int`,int`):%- [@(0.0.255) template]_<[@(0.0.255) class]_ +[*@4 C]>_&] +[s5;:Upp`:`:SubRange`(const C`&`,int`,int`):%- [@(0.0.255) auto]_[* SubRange]([@(0.0.255) c +onst]_[*@4 C][@(0.0.255) `&]_[*@3 c], [@(0.0.255) int]_[*@3 pos], [@(0.0.255) int]_[*@3 count]) +;&] +[s2; Makes a Range as subrange of some other Range (e.g. container).&] +[s3; &] +[s4;%- &] +[s5;:Upp`:`:SubRangeOf`:`:typedef:%- [@(0.0.255) template +using]_[* SubRangeOf];&] +[s2; Returns the type of SubRange of some Range.&] +[s3; &] +[s4;%- &] +[s5;:Upp`:`:ConstRange`(const T`&`,int`):%- [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 T +]>_&] +[s5;:Upp`:`:ConstRange`(const T`&`,int`):%- [_^Upp`:`:ConstRangeClass^ ConstRangeClass]< +[*@4 T]>_[* ConstRange]([@(0.0.255) const]_[*@4 T][@(0.0.255) `&]_[*@3 value], +[@(0.0.255) int]_[*@3 count])&] +[s2; Creates a Range of [%-*@3 count] elements equal to [%-*@3 value].&] +[s3; &] +[s4;%- &] +[s5;:Upp`:`:ViewRange`(BaseRange`&`,Upp`:`:Vector``&`&`):%- [@(0.0.255) template]_ +<[@(0.0.255) class]_[*@4 BaseRange]>_&] +[s5;:Upp`:`:ViewRange`(BaseRange`&`,Upp`:`:Vector``&`&`):%- [_^Upp`:`:ViewRangeClass^ V +iewRangeClass]<[*@4 BaseRange]>_[* ViewRange]([*@4 BaseRange][@(0.0.255) `&]_[*@3 r], +[_^Upp`:`:Vector^ Vector]<[@(0.0.255) int]>`&`&_[*@3 ndx])&] +[s2; Creates a view of [%-*@4 BaseRange ][%-*@3 r] based on mapping [%-*@3 ndx]. +Element at [%-*@3 ndx]`[0`] becomes a first element of a new Range, +[%-*@3 ndx]`[1`] second etc..&] +[s3; &] +[s4;%- &] +[s5;:Upp`:`:FilterRange`(BaseRange`&`,Predicate`):%- [@(0.0.255) template]_<[@(0.0.255) c +lass]_[*@4 BaseRange], [@(0.0.255) class]_[*@4 Predicate]>_&] +[s5;:Upp`:`:FilterRange`(BaseRange`&`,Predicate`):%- [_^Upp`:`:ViewRangeClass^ ViewRang +eClass]<[*@4 BaseRange]>_[* FilterRange]([*@4 BaseRange][@(0.0.255) `&]_[*@3 r], +[*@4 Predicate]_[*@3 p])&] +[s2; Same as ViewRangeClass([%-*@3 r], FindAll([%-*@3 r], +[%-*@3 p])). Creates a view of elements of master Range that satisfy +condition [%-*@3 p].&] +[s3; &] +[s0; ]] \ No newline at end of file