Bonjour,

J'aimerais effectuer un test d'égalité sur deux valeurs dans une MAP.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
 
#include <string>
#include <map>
#include <vector>
#include <algorithm>
 
struct data
{
	int value;
	std::string String;
};
 
struct header
{
	int v;
	std::string s;
};
 
class example
{
	private:
	header h_;
	data d_;
	std::map<header, std::vector<data>> container;
 
	public:
	example(const header& h, const data& d) : h_(h), d_(d) {}
 
	void processing(const int v)
	{
		auto it = std::find_if(std::begin(container), std::end(container), [&](const header& h, const data& d) -> bool { return (h_.v == h.v && d_.value == d.value); });
		if (it != std::end(container))
		{
			it->second.emplace_back(d_);
		}
		else 
		{
			container[h_].emplace_back(d_);
		}
	}
};
Je pense que les lambdas autorisent le retour multiple, à coup de surcharge de l'opérateur () et une bonne utilisation de std::pair/make_pair, non?

Merci d'avance pour vos réponses.