Map, IsAny methode exist

Noah Aas 440 Reputation points
2024-09-25T17:54:09.3+00:00

Hello,

I have a map and would like to quickly check whether all entries are true. Are there any ready-made functions or approaches? In C# there is a LinQ query. IsAny. Is there something similar in C#? //-------------------------------------------------------------------

My code and thanks for help.

class CPCBInfos
{
public:
	CPCBInfos() { IsEqual = true; SerialReadTop = ""; SerialReadBot = ""; };
	~CPCBInfos() {};
	
	CString SerialReadTop;
	CString SerialReadBot;
	bool IsEqual;
};

class CPanelInfos
{

public:
	CPanelInfos() {};
	~CPanelInfos() {};
	
	map<CString, CPCBInfos> DicIndexInfos;
	
	
25-09-2024 13:23:02.071 [CUST] Position= 1, PanelIndex= 1, SideTop= 2024-09-25-0001, SideBottom= 2024-09-25-0001, Result= 1
25-09-2024 13:23:02.071 [CUST] Position= 2, PanelIndex= 2, SideTop= 2024-09-25-0002, SideBottom= 2024-09-25-0002, Result= 1


bool CPanelInfos::IsGood()
{
	CPCBInfos value;

	CString key;
	bool ret = true;
	// Create iterator
	map<CString, CPCBInfos >::iterator itr;
	// Iterator
	for (itr = DicIndexInfos.begin(); itr != DicIndexInfos.end(); ++itr) 
	{
		key = itr->first;
		value = itr->second;

		if (value.SerialReadTop == value.SerialReadBot)
			value.IsEqual = true;
		else
		{
			value.IsEqual = false;
			ret = false;
		}
	}
	return ret;
}

enter image description here

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,717 questions
{count} votes

Accepted answer
  1. Viorel 117K Reputation points
    2024-09-25T18:19:25.6433333+00:00

    For example:

    #include <algorithm>
    
    class CPanelInfos
    {
       . . .
    
       bool AllGood( ) const
       {
          return std::all_of( DicIndexInfos.cbegin( ), DicIndexInfos.cend( ), 
             []( auto p ) { return p.second.IsEqual; } );
       }
    }
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.