Why is this code failing to compile?
std::map<SetAssignNameFunc, GetAssignNameFunc> mapAssignNameFunctions =
{
{&CChristianLifeMinistryEntry::SetVideoHost, &CChristianLifeMinistryEntry::GetVideoHost},
{&CChristianLifeMinistryEntry::SetVideoCohost, &CChristianLifeMinistryEntry::GetVideoCohost},
{&CChristianLifeMinistryEntry::SetChairman, &CChristianLifeMinistryEntry::GetChairman},
{&CChristianLifeMinistryEntry::SetAuxiliaryCounsellor1, &CChristianLifeMinistryEntry::GetAuxiliaryCounsellor1},
{&CChristianLifeMinistryEntry::SetAuxiliaryCounsellor2, &CChristianLifeMinistryEntry::GetAuxiliaryCounsellor2},
{&CChristianLifeMinistryEntry::SetOpenPrayer, &CChristianLifeMinistryEntry::GetOpenPrayer},
{&CChristianLifeMinistryEntry::SetTreasures1, &CChristianLifeMinistryEntry::GetTreasures1},
{&CChristianLifeMinistryEntry::SetTreasures2, &CChristianLifeMinistryEntry::GetTreasures2},
{&CChristianLifeMinistryEntry::SetLiving1, &CChristianLifeMinistryEntry::GetLiving1},
{&CChristianLifeMinistryEntry::SetLiving2, &CChristianLifeMinistryEntry::GetLiving2},
{&CChristianLifeMinistryEntry::SetLiving2b, &CChristianLifeMinistryEntry::GetLiving2b},
{&CChristianLifeMinistryEntry::SetCBSConductor, &CChristianLifeMinistryEntry::GetCBSConductor},
{&CChristianLifeMinistryEntry::SetCBSReader, &CChristianLifeMinistryEntry::GetCBSReader},
{&CChristianLifeMinistryEntry::SetClosePrayer, &CChristianLifeMinistryEntry::GetClosePrayer}
};
The two definitions are:
using GetAssignNameFunc = CString (CChristianLifeMinistryEntry::*)() const;
using SetAssignNameFunc = void (CChristianLifeMinistryEntry::*)(CString);
The complete code is:
std::vector<GetAssignNameFunc> CChristianLifeMinistryEditorDlg::PreprocessAutoAssignActions(const AutoAssignActionVector &vAutoAssignActions)
{
std::vector<GetAssignNameFunc> vpfnGetAssignNames;
std::map<SetAssignNameFunc, GetAssignNameFunc> mapAssignNameFunctions =
{
{&CChristianLifeMinistryEntry::SetVideoHost, &CChristianLifeMinistryEntry::GetVideoHost},
{&CChristianLifeMinistryEntry::SetVideoCohost, &CChristianLifeMinistryEntry::GetVideoCohost},
{&CChristianLifeMinistryEntry::SetChairman, &CChristianLifeMinistryEntry::GetChairman},
{&CChristianLifeMinistryEntry::SetAuxiliaryCounsellor1, &CChristianLifeMinistryEntry::GetAuxiliaryCounsellor1},
{&CChristianLifeMinistryEntry::SetAuxiliaryCounsellor2, &CChristianLifeMinistryEntry::GetAuxiliaryCounsellor2},
{&CChristianLifeMinistryEntry::SetOpenPrayer, &CChristianLifeMinistryEntry::GetOpenPrayer},
{&CChristianLifeMinistryEntry::SetTreasures1, &CChristianLifeMinistryEntry::GetTreasures1},
{&CChristianLifeMinistryEntry::SetTreasures2, &CChristianLifeMinistryEntry::GetTreasures2},
{&CChristianLifeMinistryEntry::SetLiving1, &CChristianLifeMinistryEntry::GetLiving1},
{&CChristianLifeMinistryEntry::SetLiving2, &CChristianLifeMinistryEntry::GetLiving2},
{&CChristianLifeMinistryEntry::SetLiving2b, &CChristianLifeMinistryEntry::GetLiving2b},
{&CChristianLifeMinistryEntry::SetCBSConductor, &CChristianLifeMinistryEntry::GetCBSConductor},
{&CChristianLifeMinistryEntry::SetCBSReader, &CChristianLifeMinistryEntry::GetCBSReader},
{&CChristianLifeMinistryEntry::SetClosePrayer, &CChristianLifeMinistryEntry::GetClosePrayer}
};
for (const auto& sAutoAssignAction : vAutoAssignActions)
{
vpfnGetAssignNames.push_back(mapAssignNameFunctions.at(sAutoAssignAction.pfnSetAssignName));
}
}
But when I compile:
7>xstddef(117,22): error C2296: '<': not valid as left operand has type 'const _Ty' 7> with 7> [ 7> _Ty=SetAssignNameFunc 7> ] 7>xstddef(116): message : while compiling class template member function 'bool std::less::operator ()(const _Ty &,const _Ty &) const' 7> with 7> [ 7> _Ty=SetAssignNameFunc 7> ] 7>xutility(1453): message : see reference to function template instantiation 'bool std::less::operator ()(const _Ty &,const _Ty &) const' being compiled 7> with 7> [ 7> _Ty=SetAssignNameFunc 7> ] 7>xmemory(1360): message : see reference to class template instantiation 'std::less' being compiled 7>xmemory(1360): message : see reference to variable template 'const bool is_empty_v<std::less<void (__cdecl CChristianLifeMinistryEntry::*)(ATL::CStringT<wchar_t,StrTraitMFC<wchar_t,ATL::ChTraitsCRT<wchar_t> > >)> >' being compiled 7>map(73): message : see reference to class template instantiation 'std::_Treestd::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,false>' being compiled 7> with 7> [ 7> _Kty=SetAssignNameFunc, 7> _Ty=GetAssignNameFunc, 7> _Pr=std::less, 7> _Alloc=std::allocator<std::pair<const SetAssignNameFunc,GetAssignNameFunc>> 7> ] 7>ChristianLifeMinistryEditorDlg.cpp(9502): message : see reference to class template instantiation 'std::map<SetAssignNameFunc,GetAssignNameFunc,std::less,std::allocator<std::pair<const SetAssignNameFunc,GetAssignNameFunc>>>' being compiled 7>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\xstddef(117,22): error C2297: '<': not valid as right operand has type 'const _Ty' 7> with 7> [ 7> _Ty=SetAssignNameFunc 7> ]
Update
I tried:
std::unordered_map<SetAssignNameFunc, GetAssignNameFunc, SetAssignNameFuncHash> mapAssignNameFunctions =
{
{&CChristianLifeMinistryEntry::SetVideoHost, &CChristianLifeMinistryEntry::GetVideoHost},
{&CChristianLifeMinistryEntry::SetVideoCohost, &CChristianLifeMinistryEntry::GetVideoCohost},
{&CChristianLifeMinistryEntry::SetChairman, &CChristianLifeMinistryEntry::GetChairman},
{&CChristianLifeMinistryEntry::SetAuxiliaryCounsellor1, &CChristianLifeMinistryEntry::GetAuxiliaryCounsellor1},
{&CChristianLifeMinistryEntry::SetAuxiliaryCounsellor2, &CChristianLifeMinistryEntry::GetAuxiliaryCounsellor2},
{&CChristianLifeMinistryEntry::SetOpenPrayer, &CChristianLifeMinistryEntry::GetOpenPrayer},
{&CChristianLifeMinistryEntry::SetTreasures1, &CChristianLifeMinistryEntry::GetTreasures1},
{&CChristianLifeMinistryEntry::SetTreasures2, &CChristianLifeMinistryEntry::GetTreasures2},
{&CChristianLifeMinistryEntry::SetLiving1, &CChristianLifeMinistryEntry::GetLiving1},
{&CChristianLifeMinistryEntry::SetLiving2, &CChristianLifeMinistryEntry::GetLiving2},
{&CChristianLifeMinistryEntry::SetLiving2b, &CChristianLifeMinistryEntry::GetLiving2b},
{&CChristianLifeMinistryEntry::SetCBSConductor, &CChristianLifeMinistryEntry::GetCBSConductor},
{&CChristianLifeMinistryEntry::SetCBSReader, &CChristianLifeMinistryEntry::GetCBSReader},
{&CChristianLifeMinistryEntry::SetClosePrayer, &CChristianLifeMinistryEntry::GetClosePrayer}
};
for (const auto& sAutoAssignAction : vAutoAssignActions)
{
vpfnGetAssignNames.push_back(mapAssignNameFunctions.at(sAutoAssignAction.pfnSetAssignName));
}
But I get a exception when running on this line:
vpfnGetAssignNames.push_back(mapAssignNameFunctions.at(sAutoAssignAction.pfnSetAssignName));
It says:
std::out_of_rangeat memory location
My current approach (which works) is:
std::vector<GetAssignNameFunc> CChristianLifeMinistryEditorDlg::PreprocessAutoAssignActions(const AutoAssignActionVector &vAutoAssignActions)
{
std::vector<GetAssignNameFunc> vpfnGetAssignNames;
/*
std::unordered_map<SetAssignNameFunc, GetAssignNameFunc, SetAssignNameFuncHash> mapAssignNameFunctions =
{
{&CChristianLifeMinistryEntry::SetVideoHost, &CChristianLifeMinistryEntry::GetVideoHost},
{&CChristianLifeMinistryEntry::SetVideoCohost, &CChristianLifeMinistryEntry::GetVideoCohost},
{&CChristianLifeMinistryEntry::SetChairman, &CChristianLifeMinistryEntry::GetChairman},
{&CChristianLifeMinistryEntry::SetAuxiliaryCounsellor1, &CChristianLifeMinistryEntry::GetAuxiliaryCounsellor1},
{&CChristianLifeMinistryEntry::SetAuxiliaryCounsellor2, &CChristianLifeMinistryEntry::GetAuxiliaryCounsellor2},
{&CChristianLifeMinistryEntry::SetOpenPrayer, &CChristianLifeMinistryEntry::GetOpenPrayer},
{&CChristianLifeMinistryEntry::SetTreasures1, &CChristianLifeMinistryEntry::GetTreasures1},
{&CChristianLifeMinistryEntry::SetTreasures2, &CChristianLifeMinistryEntry::GetTreasures2},
{&CChristianLifeMinistryEntry::SetLiving1, &CChristianLifeMinistryEntry::GetLiving1},
{&CChristianLifeMinistryEntry::SetLiving2, &CChristianLifeMinistryEntry::GetLiving2},
{&CChristianLifeMinistryEntry::SetLiving2b, &CChristianLifeMinistryEntry::GetLiving2b},
{&CChristianLifeMinistryEntry::SetCBSConductor, &CChristianLifeMinistryEntry::GetCBSConductor},
{&CChristianLifeMinistryEntry::SetCBSReader, &CChristianLifeMinistryEntry::GetCBSReader},
{&CChristianLifeMinistryEntry::SetClosePrayer, &CChristianLifeMinistryEntry::GetClosePrayer}
};
for (const auto& sAutoAssignAction : vAutoAssignActions)
{
vpfnGetAssignNames.push_back(mapAssignNameFunctions.at(sAutoAssignAction.pfnSetAssignName));
}
*/
const auto IsProcessingAutoAssignAction = [&](SetAssignNameFunc pfnSetAssignName)
{
for (const S_MWB_AUTO_ASSIGN_ACTION sAutoAssignAction : vAutoAssignActions)
{
if (sAutoAssignAction.pfnSetAssignName == pfnSetAssignName)
{
return true;
}
}
return false;
};
if (!IsProcessingAutoAssignAction(&CChristianLifeMinistryEntry::SetVideoHost))
{
vpfnGetAssignNames.push_back(&CChristianLifeMinistryEntry::GetVideoHost);
}
if (!IsProcessingAutoAssignAction(&CChristianLifeMinistryEntry::SetVideoCohost))
{
vpfnGetAssignNames.push_back(&CChristianLifeMinistryEntry::GetVideoCohost);
}
if (!IsProcessingAutoAssignAction(&CChristianLifeMinistryEntry::SetChairman))
{
vpfnGetAssignNames.push_back(&CChristianLifeMinistryEntry::GetChairman);
}
if (!IsProcessingAutoAssignAction(&CChristianLifeMinistryEntry::SetAuxiliaryCounsellor1))
{
vpfnGetAssignNames.push_back(&CChristianLifeMinistryEntry::GetAuxiliaryCounsellor1);
}
if (!IsProcessingAutoAssignAction(&CChristianLifeMinistryEntry::SetAuxiliaryCounsellor2))
{
vpfnGetAssignNames.push_back(&CChristianLifeMinistryEntry::GetAuxiliaryCounsellor2);
}
if (!IsProcessingAutoAssignAction(&CChristianLifeMinistryEntry::SetOpenPrayer))
{
vpfnGetAssignNames.push_back(&CChristianLifeMinistryEntry::GetOpenPrayer);
}
if (!IsProcessingAutoAssignAction(&CChristianLifeMinistryEntry::SetClosePrayer))
{
vpfnGetAssignNames.push_back(&CChristianLifeMinistryEntry::GetClosePrayer);
}
if (!IsProcessingAutoAssignAction(&CChristianLifeMinistryEntry::SetTreasures1))
{
vpfnGetAssignNames.push_back(&CChristianLifeMinistryEntry::GetTreasures1);
}
if (!IsProcessingAutoAssignAction(&CChristianLifeMinistryEntry::SetTreasures2))
{
vpfnGetAssignNames.push_back(&CChristianLifeMinistryEntry::GetTreasures2);
}
if (!IsProcessingAutoAssignAction(&CChristianLifeMinistryEntry::SetLiving1))
{
vpfnGetAssignNames.push_back(&CChristianLifeMinistryEntry::GetLiving1);
}
if (!IsProcessingAutoAssignAction(&CChristianLifeMinistryEntry::SetLiving2))
{
vpfnGetAssignNames.push_back(&CChristianLifeMinistryEntry::GetLiving2);
}
if (!IsProcessingAutoAssignAction(&CChristianLifeMinistryEntry::SetLiving2b))
{
vpfnGetAssignNames.push_back(&CChristianLifeMinistryEntry::GetLiving2b);
}
if (!IsProcessingAutoAssignAction(&CChristianLifeMinistryEntry::SetCBSConductor))
{
vpfnGetAssignNames.push_back(&CChristianLifeMinistryEntry::GetCBSConductor);
}
if (!IsProcessingAutoAssignAction(&CChristianLifeMinistryEntry::SetCBSReader))
{
vpfnGetAssignNames.push_back(&CChristianLifeMinistryEntry::GetCBSReader);
}
return vpfnGetAssignNames;
}
I have debugged and it is there:

ifchecks but the code is much longer.