Skip to content

Commit

Permalink
use structured binding declaration in range-based loops
Browse files Browse the repository at this point in the history
  • Loading branch information
cfillion committed Aug 26, 2018
1 parent 4146c94 commit dccaed3
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 31 deletions.
14 changes: 7 additions & 7 deletions src/about.cpp
Expand Up @@ -209,8 +209,8 @@ void About::setMetadata(const Metadata *metadata, const bool substitution)

const int shift = (rect.right - rect.left) + 4;

for(const auto &pair : metadata->links()) {
const int control = getLinkControl(pair.first);
for(const auto &[type, link] : metadata->links()) {
const int control = getLinkControl(type);

if(!m_links.count(control)) {
HWND handle = getControl(control);
Expand All @@ -223,7 +223,7 @@ void About::setMetadata(const Metadata *metadata, const bool substitution)
m_links[control] = {};
}

m_links[control].push_back(&pair.second);
m_links[control].push_back(&link);
}

onResize(); // update the position of link buttons
Expand Down Expand Up @@ -572,10 +572,10 @@ void AboutPackageDelegate::updateList(const int index)
if(sections) {
vector<string> sectionNames;

for(const auto &pair : sectionMap) {
if(sections & pair.first) {
sectionNames.push_back(pair.second);
sections &= ~pair.first;
for(const auto &[section, name] : sectionMap) {
if(sections & section) {
sectionNames.push_back(name);
sections &= ~section;
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/browser.cpp
Expand Up @@ -333,11 +333,10 @@ void Browser::displayButton()
if(!m_typeFilter)
menu.checkRadio(index);

for(const auto &pair : types) {
auto index = menu.addAction(pair.first,
pair.second | (ACTION_FILTERTYPE << 8));
for(const auto &[name, type] : types) {
auto index = menu.addAction(name, type | (ACTION_FILTERTYPE << 8));

if(m_typeFilter && m_typeFilter == pair.second)
if(m_typeFilter && m_typeFilter == type)
menu.checkRadio(index);
}

Expand Down
4 changes: 1 addition & 3 deletions src/dialog.cpp
Expand Up @@ -455,9 +455,7 @@ void Dialog::onNotify(LPNMHDR info, LPARAM lParam)

void Dialog::onContextMenu(HWND target, const int x, const int y)
{
for(const auto &pair : m_controls) {
Control *ctrl = pair.second;

for(Control *ctrl : m_controls | boost::adaptors::map_values) {
if(!IsWindowVisible(ctrl->handle()))
continue;

Expand Down
4 changes: 2 additions & 2 deletions src/thread.cpp
Expand Up @@ -211,8 +211,8 @@ void ThreadNotifier::processQueue()
lock_guard<mutex> guard(m_mutex);

while(!m_queue.empty()) {
const Notification &notif = m_queue.front();
notif.first->setState(notif.second);
const auto &[task, state] = m_queue.front();
task->setState(state);
m_queue.pop();
}
}
6 changes: 3 additions & 3 deletions src/transaction.cpp
Expand Up @@ -264,9 +264,9 @@ void Transaction::registerScript(const HostTicket &reg, const bool isLastCall)

vector<int> sections;

for(const auto &pair : sectionMap) {
if(reg.file.sections & pair.first)
sections.push_back(pair.second);
for(const auto &[flag, id] : sectionMap) {
if(reg.file.sections & flag)
sections.push_back(id);
}

assert(!sections.empty()); // is a section missing in sectionMap?
Expand Down
8 changes: 4 additions & 4 deletions test/package.cpp
Expand Up @@ -24,8 +24,8 @@ TEST_CASE("package type from string", M) {
{"autoitem", Package::AutomationItemType},
};

for(const auto &pair : tests)
REQUIRE(Package::getType(pair.first) == pair.second);
for(const auto &[typeString, typeId] : tests)
REQUIRE(Package::getType(typeString) == typeId);
}

TEST_CASE("package type to string", M) {
Expand All @@ -45,8 +45,8 @@ TEST_CASE("package type to string", M) {
{static_cast<Package::Type>(-1), "Unknown"},
};

for(const auto &pair : tests)
REQUIRE(Package::displayType(pair.first) == pair.second);
for(const auto &[type, displayName] : tests)
REQUIRE(Package::displayType(type) == displayName);
}

TEST_CASE("invalid package name", M) {
Expand Down
6 changes: 3 additions & 3 deletions test/platform.cpp
Expand Up @@ -50,7 +50,7 @@ TEST_CASE("platform from string", M) {
}

TEST_CASE("test platform", M) {
const pair<Platform, bool> expected[] = {
const pair<Platform, bool> tests[] = {
{Platform::GenericPlatform, true},

#ifdef __APPLE__
Expand Down Expand Up @@ -104,6 +104,6 @@ TEST_CASE("test platform", M) {
#endif
};

for(const auto &it : expected)
REQUIRE(it.first.test() == it.second);
for(const auto &[platform, expected] : tests)
REQUIRE(platform.test() == expected);
}
6 changes: 3 additions & 3 deletions test/source.cpp
Expand Up @@ -148,9 +148,9 @@ TEST_CASE("source target path", M) {
};

Source source("file.name", "url", &ver);
for(const auto &pair : tests) {
source.setTypeOverride(pair.first);
REQUIRE(source.targetPath() == Path(pair.second));
for(const auto &[type, path] : tests) {
source.setTypeOverride(type);
REQUIRE(source.targetPath() == Path(path));
}
}

Expand Down
3 changes: 1 addition & 2 deletions win32.tup
Expand Up @@ -9,8 +9,7 @@ REAPACK_FILE := reaper_reapack@(SUFFIX)

VCPKG = vendor/vcpkg/installed/@(VCPKG_TRIPLET)

CXXFLAGS := /nologo /W3 /WX /wd4996 /EHsc /MT
CXXFLAGS += /O2 /Z7 /Zo
CXXFLAGS := /nologo /std:c++17 /W3 /WX /wd4996 /EHsc /MT /O2 /Z7 /Zo
CXXFLAGS += /Ivendor /I$(VCPKG)/include /Ivendor/WDL /Ivendor/WDL/WDL
CXXFLAGS += /DWDL_NO_DEFINE_MINMAX /DCURL_STATICLIB /DUNICODE /DNDEBUG
CXXFLAGS += /DREAPACK_FILE#\"$(REAPACK_FILE).dll\"
Expand Down

0 comments on commit dccaed3

Please sign in to comment.