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 » U++ Library support » U++ Core » Copy the content of a SortedVectorMap
Copy the content of a SortedVectorMap [message #60732] Wed, 07 August 2024 19:52 Go to next message
forlano is currently offline  forlano
Messages: 1207
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

I have two SortedVectorMap

SortedVectorMap<int, PlayerTB> TBVega, TBS;

where

class PlayerTB : Moveable<PlayerTB> {
public:
	int id;
	int rank;
	Vector<String> tbs;	
	PlayerTB() {}
};


At some moment I would like that the content of TBVega be identical to that of TBS but without loosing/destroying the content of TBS.
Of course I can iterate and copy one by one the elements. I would like to know if there is some efficient way to do it. I read about clone but the compiler complain things that I do not understand. Perhaps I need to do something on class PlayerTB.

 note: copy constructor of 'PlayerTB' is implicitly deleted because field 'tbs' has a deleted copy constructor
        Vector<String> tbs;     
                       ^
C:\upp/uppsrc/Core/Vcont.h:290:2: note: copy constructor is implicitly deleted because 'Vector<Upp::String>' has a user-declared move construct
    or
        Vector(Vector&& v)               { Pick(pick(v)); }
        ^


Thanks,
Luigi

[Updated on: Wed, 07 August 2024 19:53]

Report message to a moderator

Re: Copy the content of a SortedVectorMap [message #60734 is a reply to message #60732] Mon, 12 August 2024 23:14 Go to previous messageGo to next message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 227
Registered: June 2011
Experienced Member
Luigi,

I don't exactly grasp what you're trying to accomplish but if you want clone semantics you can accomplish it this way:

#include <Core/Core.h>

using namespace Upp;

class PlayerTB : MoveableAndDeepCopyOption<PlayerTB> {
public:
    int id;
    int rank;
    Vector<String> tbs;
    
    PlayerTB(const PlayerTB& other, int) {
        id   = other.id;
        rank = other.rank;
        tbs  = clone(other.tbs);
    }
    
    PlayerTB() = default;
};

template <>
inline auto Upp::AsString(const PlayerTB& props) -> String {
    return Format(
        "PlayerTB: {\n"
        "    id:   %s\n"
        "    rank: %s\n"
        "    tbs:  %s\n"
        "}",
        FormatInt(props.id),
        FormatInt(props.rank),
        AsString(props.tbs));
}

CONSOLE_APP_MAIN {
    SortedVectorMap<int, PlayerTB> TBVega, TBS;
    
    auto& t = TBVega.Add(1);
    t.id = 1;
    t.rank = 2;
    t.tbs.Append({ "test", "test2" });
    
    auto& t2 = TBS.Add(2);
    t2.id = 2;
    t2.rank = 3;
    t2.tbs.Append({ "test3", "test4"});
    
    LOG("=== Before clone ===");
    LOG(TBVega);
    LOG(TBS);
    
    TBVega = clone(TBS);
    
    LOG("=== After clone ===");
    LOG(TBVega);
    LOG(TBS);
}


Log:

=== Before clone ===
{1: PlayerTB: {
    id:   1
    rank: 2
    tbs:  [test, test2]
}}
{2: PlayerTB: {
    id:   2
    rank: 3
    tbs:  [test3, test4]
}}
=== After clone ===
{2: PlayerTB: {
    id:   2
    rank: 3
    tbs:  [test3, test4]
}}
{2: PlayerTB: {
    id:   2
    rank: 3
    tbs:  [test3, test4]
}}
Re: Copy the content of a SortedVectorMap [message #60735 is a reply to message #60734] Tue, 13 August 2024 23:33 Go to previous message
forlano is currently offline  forlano
Messages: 1207
Registered: March 2006
Location: Italy
Senior Contributor
Thank you!

I wanted to do what you did.

Best regards,
Luigi
Previous Topic: HowTO use Core/SSH with PRIV/PUB Keys ?
Next Topic: How to mark std::array<T, N> moveable if only T is moveable
Goto Forum:
  


Current Time: Mon Jun 09 18:30:16 CEST 2025

Total time taken to generate the page: 0.04027 seconds