Skip to content

Can I simplify this lambda? #8

@ajtruckle

Description

@ajtruckle

As you can see from the code below, I use find_element to drill down to tthe desired week in the XML file:

auto pWeek = tinyxml2::find_element(doc, stdWeekPath);
if (pWeek != nullptr)
{
	auto UpdateAssignForWeek = [this, listMidweekAssign, pWeek, pEntry](int iAssign, const char* strElement, MWBAuto::SetAssignNameFunc fncSetAssignName)
	{
		if (listMidweekAssign.at(iAssign)) // Host
		{
			const tinyxml2::XMLElement* pElement = pWeek->FirstChildElement(strElement);
			if (pElement == nullptr)
			{
				AfxThrowMemoryException();
			}

			CString strNameToUse;
			strNameToUse = CA2CT(pElement->GetText(), CP_UTF8);
			(pEntry->*fncSetAssignName)(strNameToUse);
		}
	};

	UpdateAssignForWeek(0, kVideoConferenceHost, &CChristianLifeMinistryEntry::SetVideoHost);
	UpdateAssignForWeek(1, kVideoConferenceCohost, &CChristianLifeMinistryEntry::SetVideoCohost);
	UpdateAssignForWeek(2, kChairman, &CChristianLifeMinistryEntry::SetChairman);

	if (iDate == m_iDateIndex)
	{
		DisplayMeetingForDate();
	}
}

But can the lambda be simplified? Where it get the text of the sub element? Do you have a helper for that? Sorry if I missed in the sample.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions