diff --git a/autotest/BiCreate/BiCreate.cpp b/autotest/BiCreate/BiCreate.cpp new file mode 100644 index 000000000..ac83bd5bc --- /dev/null +++ b/autotest/BiCreate/BiCreate.cpp @@ -0,0 +1,45 @@ +#include + +using namespace Upp; + +struct Foo : Tuple2 { + int c; + + Foo(int a, int b, int c) : Tuple2(a, b), c(c) {} +}; + +CONSOLE_APP_MAIN +{ + StdLogSetup(LOG_COUT|LOG_FILE); + + { + BiVector> m; + + m.CreateTail(3, 4); + m.CreateHead(1, 2); + + DDUMP(m); + } + + { + BiArray> m; + + m.CreateTail(7, 8); + m.CreateHead(5, 6); + + DDUMP(m); + } + + { + BiArray> m; + + m.CreateTail(11, 12, 13); + m.CreateHead(9, 10); + + DDUMP(m); + + DDUMP(((Foo&)m.Tail()).c); + } + + CheckLogEtalon(); +} diff --git a/autotest/BiCreate/BiCreate.upp b/autotest/BiCreate/BiCreate.upp new file mode 100644 index 000000000..3f43965b4 --- /dev/null +++ b/autotest/BiCreate/BiCreate.upp @@ -0,0 +1,10 @@ +uses + Core; + +file + Etalon.log, + BiCreate.cpp; + +mainconfig + "" = ""; + diff --git a/autotest/BiCreate/Etalon.log b/autotest/BiCreate/Etalon.log new file mode 100644 index 000000000..e215e4c8a --- /dev/null +++ b/autotest/BiCreate/Etalon.log @@ -0,0 +1,6 @@ +* C:\upp\out\autotest\CLANGx64.Debug.Debug_Full\BiCreate.exe 16.05.2022 13:32:31, user: cxl + +m = [(1, 2), (3, 4)] +m = [(5, 6), (7, 8)] +m = [(9, 10), (11, 12)] +((Foo&)m.Tail()).c = 13 diff --git a/uppsrc/Core/BiCont.h b/uppsrc/Core/BiCont.h index 4e85a1bb0..ced6ec63a 100644 --- a/uppsrc/Core/BiCont.h +++ b/uppsrc/Core/BiCont.h @@ -27,6 +27,10 @@ public: T& AddHead() { return *new(AddHead0()) T; } T& AddTail() { return *new(AddTail0()) T; } + template + T& CreateHead(Args&&... args) { return *new(AddHead0()) T(std::forward(args)...); } + template + T& CreateTail(Args&&... args) { return *new(AddTail0()) T(std::forward(args)...); } void AddHead(const T& x) { new(AddHead0()) T(x); } void AddTail(const T& x) { new(AddTail0()) T(x); } void AddHead(T&& x) { new(AddHead0()) T(pick(x)); } @@ -108,8 +112,14 @@ public: void AddTail(const T& x) { bv.AddTail(new T(x)); } T& AddHead(T *newt) { bv.AddHead(newt); return *newt; } T& AddTail(T *newt) { bv.AddTail(newt); return *newt; } - template TT& CreateHead() { TT *q = new TT; bv.AddHead(q); return *q; } - template TT& CreateTail() { TT *q = new TT; bv.AddTail(q); return *q; } + template + T& CreateHead(Args&&... args) { T *q = new T(std::forward(args)...); bv.AddHead(q); return *q; } + template + T& CreateTail(Args&&... args) { T *q = new T(std::forward(args)...); bv.AddTail(q); return *q; } + template + TT& CreateHead(Args&&... args) { TT *q = new TT(std::forward(args)...); bv.AddHead(q); return *q; } + template + TT& CreateTail(Args&&... args) { TT *q = new TT(std::forward(args)...); bv.AddTail(q); return *q; } T& AddHead(One&& one) { ASSERT(one); return AddHead(one.Detach()); } T& AddTail(One&& one) { ASSERT(one); return AddTail(one.Detach()); } T& Head() { return *(T *) bv.Head(); } diff --git a/uppsrc/Core/src.tpp/BiArray_en-us.tpp b/uppsrc/Core/src.tpp/BiArray_en-us.tpp index bbf8d2821..c46331518 100644 --- a/uppsrc/Core/src.tpp/BiArray_en-us.tpp +++ b/uppsrc/Core/src.tpp/BiArray_en-us.tpp @@ -166,14 +166,30 @@ be at position GetCount() `- 1.&] [s7; [*/ Return value]-|Reference to the object `- [* `*newt].&] [s3; &] [s4;%- &] +[s5;:Upp`:`:BiArray`:`:CreateHead`(Args`&`&`.`.`.args`):%- [@(0.0.255) template]_<[@(0.0.255) c +lass...]_[*@4 Args]>_[*@4 T][@(0.0.255) `&]_[* CreateHead]([*@4 Args][@(0.0.255) `&`&...]_[*@3 a +rgs])&] +[s2; Creates a new element at the head with [%-*@3 args] constructor +parameters.&] +[s3; &] +[s4;%- &] +[s5;:Upp`:`:BiArray`:`:CreateTail`(Args`&`&`.`.`.args`):%- [@(0.0.255) template]_<[@(0.0.255) c +lass...]_[*@4 Args]>_[*@4 T][@(0.0.255) `&]_[* CreateTail]([*@4 Args][@(0.0.255) `&`&...]_[*@3 a +rgs])&] +[s2; Creates a new element at the tail with [%-*@3 args] constructor +parameters.&] +[s3; &] +[s4;%- &] [s5;:Upp`:`:BiArray`:`:CreateHead`(`):%- [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 TT]> -_[*@4 TT][@(0.0.255) `&]_[* CreateHead]()&] -[s2; Creates a new element of type [%-*@4 TT] at the head.&] +_[*@4 TT][@(0.0.255) `&]_[* CreateHead]([*@4 Args][@(0.0.255) `&`&...]_[*@3 args])&] +[s2; Creates a new element of type [%-*@4 TT] at the head with [%-*@3 args] +constructor parameters.&] [s3;%- &] [s4;%- &] [s5;:Upp`:`:BiArray`:`:CreateTail`(`):%- [@(0.0.255) template]_<[@(0.0.255) class]_[*@4 TT]> -_[*@4 TT][@(0.0.255) `&]_[* CreateTail]()&] -[s2; Creates a new element of type [%-*@4 TT] at the tail.&] +_[*@4 TT][@(0.0.255) `&]_[* CreateTail]([*@4 Args][@(0.0.255) `&`&...]_[*@3 args])&] +[s2; Creates a new element of type [%-*@4 TT] at the tail with [%-*@3 args] +constructor parameters.&] [s3;%- &] [s4;%- &] [s5;:Upp`:`:BiArray`:`:AddHead`(Upp`:`:One``&`&`):%- [*@4 T][@(0.0.255) `&]_[* AddHead]( diff --git a/uppsrc/Core/src.tpp/BiVector_en-us.tpp b/uppsrc/Core/src.tpp/BiVector_en-us.tpp index ef542ee25..4c7df3b00 100644 --- a/uppsrc/Core/src.tpp/BiVector_en-us.tpp +++ b/uppsrc/Core/src.tpp/BiVector_en-us.tpp @@ -88,6 +88,20 @@ reference to the newly added default constructed element.&] [s6; Invalidates iterators and references to the BiVector.&] [s3;%- &] [s4;%- &] +[s5;:Upp`:`:BiVector`:`:CreateHead`(Args`&`&`.`.`.args`):%- [@(0.0.255) template]_<[@(0.0.255) c +lass...]_[*@4 Args]>_[*@4 T][@(0.0.255) `&]_[* CreateHead]([*@4 Args][@(0.0.255) `&`&...]_[*@3 a +rgs])&] +[s2; Creates a new element at the head with [%-*@3 args] constructor +parameters.&] +[s3; &] +[s4;%- &] +[s5;:Upp`:`:BiVector`:`:CreateTail`(Args`&`&`.`.`.args`):%- [@(0.0.255) template]_<[@(0.0.255) c +lass...]_[*@4 Args]>_[*@4 T][@(0.0.255) `&]_[* CreateTail]([*@4 Args][@(0.0.255) `&`&...]_[*@3 a +rgs])&] +[s2; Creates a new element at the tail with [%-*@3 args] constructor +parameters.&] +[s3; &] +[s4;%- &] [s5;:BiVector`:`:AddHead`(const T`&`):%- [@(0.0.255) void]_[* AddHead]([@(0.0.255) const]_[*@4 T ][@(0.0.255) `&]_[*@3 x])&] [s2; Adds a new element with the specified value [%-*@3 x ]at the head diff --git a/uppsrc/TextDiffCtrl/PatchDiff.cpp b/uppsrc/TextDiffCtrl/PatchDiff.cpp index e000a450e..07db4e7b8 100644 --- a/uppsrc/TextDiffCtrl/PatchDiff.cpp +++ b/uppsrc/TextDiffCtrl/PatchDiff.cpp @@ -161,7 +161,7 @@ bool PatchDiff::Open(const char *patch_path, const Vector& target_dirs0) failed.Show(failed_count); failed.SetInk(SRed()); - failed = String() << failed_count << " file(s) failed"; + failed = String() << failed_count << " failed"; ShowResult();