c++ - 我可以简化这个 std::list 的数量吗?
问题描述
我可以简化std::list
代码的填充:
void CMeetingScheduleAssistantApp::InitBrowserRegistryLookupList(RegistryPathList& rListRegPaths)
{
S_REGISTRY_PATH sRegPath;
// Reset the list
rListRegPaths.clear();
// These will be "native" 32bit or native 64bit browsers (i.e. the Operating System bitness)
sRegPath.hRootKey = HKEY_LOCAL_MACHINE;
sRegPath.strKeyPath = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\firefox.exe");
sRegPath.strBrowser = _T("Firefox");
rListRegPaths.push_back(sRegPath);
sRegPath.hRootKey = HKEY_LOCAL_MACHINE;
sRegPath.strKeyPath = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE");
sRegPath.strBrowser = _T("Internet Explorer");
rListRegPaths.push_back(sRegPath);
sRegPath.hRootKey = HKEY_LOCAL_MACHINE;
sRegPath.strKeyPath = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe");
sRegPath.strBrowser = _T("Google Chrome");
rListRegPaths.push_back(sRegPath);
sRegPath.hRootKey = HKEY_CURRENT_USER;
sRegPath.strKeyPath = _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\opera.exe");
sRegPath.strBrowser = _T("Opera Internet Browser");
rListRegPaths.push_back(sRegPath);
// These will be 32 bit browsers (on a 64 bit Operating System)
if (IsOS(OS_WOW6432))
{
sRegPath.hRootKey = HKEY_LOCAL_MACHINE;
sRegPath.strKeyPath = _T("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\App Paths\\firefox.exe");
sRegPath.strBrowser = _T("Firefox");
rListRegPaths.push_back(sRegPath);
sRegPath.hRootKey = HKEY_LOCAL_MACHINE;
sRegPath.strKeyPath = _T("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE");
sRegPath.strBrowser = _T("Internet Explorer");
rListRegPaths.push_back(sRegPath);
sRegPath.hRootKey = HKEY_LOCAL_MACHINE;
sRegPath.strKeyPath = _T("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe");
sRegPath.strBrowser = _T("Google Chrome");
rListRegPaths.push_back(sRegPath);
}
}
更新
的定义RegPathlist
:
typedef struct tagRegistryPath
{
HKEY hRootKey;
CString strBrowser;
CString strKeyPath;
} S_REGISTRY_PATH;
using RegistryPathList = list<S_REGISTRY_PATH>;
解决方案
可能你会想要emplace_back
你的元素,这可以加速和“简化”(主观术语)你的代码。例子:
rListRegPaths.emplace_back(
HKEY_LOCAL_MACHINE,
_T("SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\App Paths\\firefox.exe"),
_T("Firefox"));
推荐阅读
- php - Laravel - 将自定义样式添加到现有的 app.scss
- java - IntelliJ 会打开 java.lang 类,尽管它在调试期间没有介入其中
- javascript - 为什么 AngularJs 不在页面更改时呈现指令?
- excel - 来自 Excel 的 XML 具有多次放置的元素但不同的属性
- rest - Docker:java.net.ConnectException:连接被拒绝 - 在端口 8083 上运行的应用程序无法访问端口 3000 上的其他应用程序
- c - 如何在 getchar()!=EOF 上获取最后一个字符
- java - Spring Boot java.sql.SQLException:字段“id”没有默认值
- android - RxJava - 如何根据第二个响应重复两个 observable
- exception - 将 mule 从 3.8 升级到 3.9 后出现加密错误
- xamarin - 是否可以使用 Microsoft App Center 记录用户使用 Xamarin Forms 应用程序执行的操作等信息?