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 » VectorMap iteration
VectorMap iteration [message #61773] Fri, 08 August 2025 12:06 Go to next message
mdelfede is currently offline  mdelfede
Messages: 1310
Registered: September 2007
Ultimate Contributor
Hello,

Why
VectorMap<String, String> map;
for(const auto &[name, value] : map) {
....

Doesn't work ? I get this error:

C:\Users\massimo\Documents\upp\UppHub\SysExec\SysExec\SysExec.cpp (242): error C2248: 'Upp::String::len': impossibile accedere a private membro dichiarato nella classe 'Upp::String'


For Vector<String> works flawlessly...
Re: VectorMap iteration [message #61774 is a reply to message #61773] Fri, 08 August 2025 12:17 Go to previous messageGo to next message
Oblivion is currently offline  Oblivion
Messages: 1223
Registered: August 2007
Senior Contributor
Hi Massimo,

It does work. You need to use tilde (~) operator, which returns KeyValueRef:

#include <Core/Core.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
	StdLogSetup(LOG_COUT);
	VectorMap<int, String> m = { {1, "one"}, {2, "two"}};
	for(const auto& [i, s] : ~m)
		LOG("i: " << i << ", s: " << s);
}



Best regards,
Oblivion


[Updated on: Fri, 08 August 2025 12:19]

Report message to a moderator

Re: VectorMap iteration [message #61775 is a reply to message #61774] Fri, 08 August 2025 16:38 Go to previous message
mdelfede is currently offline  mdelfede
Messages: 1310
Registered: September 2007
Ultimate Contributor
Thank you, Oblivion!
Previous Topic: include an excel file in the program
Next Topic: Add compilable testcases for nontrivial problems!
Goto Forum:
  


Current Time: Mon Aug 11 23:27:32 CEST 2025

Total time taken to generate the page: 0.04325 seconds