Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » [Solved]Vector<Vector<int>> problem
[Solved]Vector<Vector<int>> problem [message #53045] Mon, 17 February 2020 05:21 Go to next message
bozero is currently offline  bozero
Messages: 20
Registered: June 2018
Promising Member
Hi, everyone:

Please advise me how to fix the below problem.

#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
	Vector<int> vi1,vi2;
	Vector<Vector<int>> vvi;
	vi1<<1<<2;
	vi2<<3<<4;
	vvi<<vi1<<vi2;
	DUMP(vvi); // vvi = [[1, 2], [3, 4]]
}

and got error message:
...upp/uppsrc/Core/Vcont.h:104:7: note: 'constexpr Upp::Vector<int>::Vector(const Upp::Vector<int>&)'
     is implicitly declared as deleted because 'Upp::Vector<int>' declares a move constructor or move assignment operator
 class Vector : public MoveableAndDeepCopyOption< Vector<T> > {
       ^~~~~~
Test: 1 file(s) built in (0:02.91), 2918 msecs / file, duration = 2918 msecs

There were errors. (0:03.34)

The code is working on upp-mingw-11873,
but not work on upp-mingw-13664 & upp-mingw-13916.
under windows 10.

I am sorry for my stupid question and poor english.

Thank you very much

[Updated on: Wed, 19 February 2020 03:50]

Report message to a moderator

Re: Vector<Vector<int>> problem [message #53047 is a reply to message #53045] Mon, 17 February 2020 09:19 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3377
Registered: August 2008
Senior Veteran
In my case I get this error in MinGW:
error: use of deleted function 'constexpr Upp::Vector<int>::Vector(const Upp::Vector<int>&)'

and this in MSVC:
C:\upp\uppsrc\Core\Vcont.h(132): error C2280: 'Upp::Vector<int>::Vector(const Upp::Vector<int> &)': attempting to reference a deleted function
C:\upp\uppsrc\Core\Vcont.h(258): note: compiler has generated 'Upp::Vector<int>::Vector' here
C:\upp\uppsrc\Core\Vcont.h(258): note: 'Upp::Vector<int>::Vector(const Upp::Vector<int> &)': function was implicitly deleted because 'Upp::Vector<int>' has a user-defined move constructor
C:\upp\uppsrc\Core\Vcont.h(132): note: while compiling class template member function 'T &Upp::Vector<T>::Add(co
nst T &)' with
[
T=Upp::Vector<int>
]
C:\upp\uppsrc\Core\Vcont.h(197): note: see reference to function template instantiation 'T &Upp::Vector<T>::Add(const T &)' being compiled with
[
T=Upp::Vector<int>
]
C:\upp\uppsrc\Core\InVector.h(33): note: see reference to class template instantiation 'Upp::Vector<Upp::Vector<int>>' being compiled
C:\upp\uppsrc\Core\InVector.h(176): note: see reference to class template instantiation 'Upp::InVector<T>' being compiled


Best regards
Iñaki
Re: Vector<Vector<int>> problem [message #53062 is a reply to message #53045] Tue, 18 February 2020 18:43 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1371
Registered: December 2006
Ultimate Contributor
bozero wrote on Sun, 16 February 2020 23:21

The code is working on upp-mingw-11873,

This code is not supposed to compile with any compiler and latest version of Upp.
There are two issues with this code.
1. You are supposed to tell explicitly what you want to do with your Vector.
	vvi.Add(clone(vi1));
	vvi.Add(pick(vi2));

In the first case you are making a copy, in second - moving.
2. There is a problem with
Vector&  operator<<(const T& x)

It is supposed to look like below. This version of operator<< is missing.
Vector&  operator<<(T&& x)  { Add(pick(x)); return *this; }


In this case you would be able to write
vvi << pick(vi1) << pick(vi2);

Hope this helps.


Regards,
Novo
Re: Vector<Vector<int>> problem [message #53065 is a reply to message #53062] Tue, 18 February 2020 19:00 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1371
Registered: December 2006
Ultimate Contributor
Second issue has been fixed in svn/git already.

Regards,
Novo
Re: Vector<Vector<int>> problem [message #53067 is a reply to message #53065] Wed, 19 February 2020 03:49 Go to previous messageGo to next message
bozero is currently offline  bozero
Messages: 20
Registered: June 2018
Promising Member
Hi! Novo, koldo
Thank you for your reply.

The problem is solve by: vvi.Add(clone(vi1)); vvi.Add(pick(vi2)); // just a bit more typing

About method chaining of "<<", it seem not ready on upp-mingw-14027.
Re: Vector<Vector<int>> problem [message #53072 is a reply to message #53067] Wed, 19 February 2020 17:28 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3377
Registered: August 2008
Senior Veteran
Very interesting, thank you Novo

vvi << pick(vi1) << pick(vi2);


operator<< is very handy, but has to be handled with care when managing more complex data than basic C types.


Best regards
Iñaki
Re: Vector<Vector<int>> problem [message #56250 is a reply to message #53062] Sun, 14 February 2021 04:08 Go to previous messageGo to next message
JeyCi is currently offline  JeyCi
Messages: 50
Registered: July 2020
Member
Novo wrote on Tue, 18 February 2020 18:43

There are two issues with this code.
In the first case you are making a copy, in second - moving.
Hope this helps.

Novo, thanks for superior explanation! I missed very much this in my class-design - will check thoroughly! Rolling Eyes


Best regards.
Re: Vector<Vector<int>> problem [message #56271 is a reply to message #56250] Mon, 15 February 2021 15:53 Go to previous message
Novo is currently offline  Novo
Messages: 1371
Registered: December 2006
Ultimate Contributor
JeyCi wrote on Sat, 13 February 2021 22:08
Novo wrote on Tue, 18 February 2020 18:43

There are two issues with this code.
In the first case you are making a copy, in second - moving.
Hope this helps.

Novo, thanks for superior explanation! I missed very much this in my class-design - will check thoroughly! Rolling Eyes

No problem. That was quick - less than a year... Smile


Regards,
Novo
Previous Topic: Get volume name of shares ...
Next Topic: error: call to implicitly-deleted copy constructor
Goto Forum:
  


Current Time: Sun Jul 21 14:57:20 CEST 2024

Total time taken to generate the page: 0.02841 seconds