C++ vector - find elements inside a vector and create a new vector

Markus Freitag 3,791 Reputation points
2022-10-14T04:47:53.687+00:00

Hello,
Unfortunately, there is still a problem.
https://learn.microsoft.com/en-us/answers/questions/1031079/c-vector-find-element.html

struct PanelData  
{  
	 // **   
	 CString Price;  
	 CString IdentNo;  
  
	 bool    PanelReported;  
  
};  
  
vector<PanelData>      m_dequePanelData;  
vector<PanelData>      m_Result;  
  

Is there a way that returns me a new vector list, here all values of the PanelReported variable is true.

std::vector<PanelData>::iterator it;  
 it = find(m_dequePanelData.begin(), m_dequePanelData.end(),  []( const PanelData& d ) { return d.PanelReported; }  );	   
 //std::vector<PanelData>::iterator it2;  
 //auto it2 = find(m_dequePanelData.begin(), m_dequePanelData.end(), [](const PanelData& d) { return d.PanelReported; });  
	  
//In C# I have FirstOrDefault() or ToList()  I am looking for similar.  
//What is the correct name in C++, what functions are similar?	   
  
The simplest solution just go through the list, think a std function is faster, better.  
for (auto it = m_DicProcessdata.begin(); it != m_DicProcessdata.end(); ++it)  
{	   

Thanks!

Developer technologies | C++
{count} votes

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.