Use initializer lists rather than std::make_pair

This commit is contained in:
Thomas Goyne 2014-05-25 07:41:21 -07:00
parent 4f65f79f1e
commit 20a7ec786f
18 changed files with 29 additions and 27 deletions

View file

@ -49,7 +49,7 @@ std::pair<size_t, size_t> find_range(std::string const& haystack, std::string co
const size_t match_start = haystack.find(needle, start);
if (match_start == std::string::npos)
return bad_match;
return std::make_pair(match_start, match_start + needle.size());
return {match_start, match_start + needle.size()};
}
}
@ -115,7 +115,7 @@ std::pair<size_t, size_t> ifind(std::string const& haystack, std::string const&
if (folded_pos > match.second)
return bad_match;
return std::make_pair(start, distance(begin(haystack), begin(*haystack_it)));
return {start, distance(begin(haystack), begin(*haystack_it))};
};
auto ret = map_folded_to_raw();

View file

@ -32,4 +32,4 @@ namespace agi {
/// Get index in bytes of the nth character in str, or str.size() if str
/// has less than n characters
size_t IndexOfCharacter(std::string const& str, size_t n);
}
}

View file

@ -102,7 +102,7 @@ public:
template<size_t N>
Hotkey(agi::fs::path const& file, const char (&default_config)[N])
: Hotkey(file, std::make_pair(default_config, N - 1)) { }
: Hotkey(file, {default_config, N - 1}) { }
/// Scan for a matching key.
/// @param context Context requested.

View file

@ -58,7 +58,7 @@ public:
template<size_t N>
MRUManager(agi::fs::path const& file, const char (&default_config)[N])
: MRUManager(file, std::make_pair(default_config, N - 1)) { }
: MRUManager(file, {default_config, N - 1}) { }
/// Destructor
~MRUManager();

View file

@ -72,7 +72,7 @@ public:
template<size_t N>
Options(agi::fs::path const& file, const char (&default_config)[N], const OptionSetting setting = NONE)
: Options(file, std::make_pair(default_config, N - 1), setting) { }
: Options(file, {default_config, N - 1}, setting) { }
/// Destructor
~Options();

View file

@ -135,7 +135,7 @@ class Signal final : private detail::SignalBase {
UnscopedConnection DoConnect(Slot sig) {
auto token = MakeToken();
slots.insert(std::make_pair(token, sig));
slots.emplace(token, sig);
return UnscopedConnection(token);
}

View file

@ -233,7 +233,7 @@ void AssFile::Sort(EntryList<AssDialogue> &lst, CompFunc comp, std::set<AssDialo
uint32_t AssFile::AddExtradata(std::string const& key, std::string const& value) {
// next_extradata_id must not exist
assert(Extradata.find(next_extradata_id) == Extradata.end());
Extradata[next_extradata_id] = std::make_pair(key, value);
Extradata[next_extradata_id] = {key, value};
return next_extradata_id++; // return old value, then post-increment
}

View file

@ -219,7 +219,7 @@ void AssParser::ParseExtradataLine(std::string const &data) {
// ensure next_extradata_id is always at least 1 more than the largest existing id
target->next_extradata_id = std::max(id+1, target->next_extradata_id);
target->Extradata[id] = std::make_pair(key, value);
target->Extradata[id] = {key, value};
}
}

View file

@ -139,7 +139,7 @@ void DialogAutosave::Populate(std::map<wxString, AutosaveFile> &files_map, std::
auto it = files_map.find(name);
if (it == files_map.end())
it = files_map.insert(std::make_pair(name, AutosaveFile{name})).first;
it = files_map.insert({name, AutosaveFile{name}}).first;
it->second.versions.push_back(Version{wxFileName(directory, fn).GetFullPath(), date, wxString::Format(name_fmt, date.Format())});
} while (dir.GetNext(&fn));
}

View file

@ -625,7 +625,7 @@ void DialogKanjiTimer::OnAccept(wxCommandEvent &) {
if (display->GetRemainingSource() > 0)
wxMessageBox(_("Group all of the source text."),_("Error"),wxICON_EXCLAMATION | wxOK);
else {
LinesToChange.push_back(std::make_pair(currentDestinationLine, display->GetOutputLine()));
LinesToChange.emplace_back(currentDestinationLine, display->GetOutputLine());
currentSourceLine = FindNextStyleMatch(currentSourceLine, from_wx(SourceStyle->GetValue()));
currentDestinationLine = FindNextStyleMatch(currentDestinationLine, from_wx(DestStyle->GetValue()));

View file

@ -174,7 +174,7 @@ void DialogProperties::AddProperty(wxSizer *sizer, wxString const& label, std::s
wxTextCtrl *ctrl = new wxTextCtrl(this, -1, to_wx(c->ass->GetScriptInfo(property)), wxDefaultPosition, wxSize(200, 20));
sizer->Add(new wxStaticText(this, -1, label), wxSizerFlags().Center().Left());
sizer->Add(ctrl, wxSizerFlags(1).Expand());
properties.push_back(std::make_pair(property, ctrl));
properties.push_back({property, ctrl});
}
void DialogProperties::OnOK(wxCommandEvent &) {

View file

@ -291,7 +291,7 @@ OpenGLTextGlyph const& OpenGLText::GetGlyph(int i) {
}
OpenGLTextGlyph const& OpenGLText::CreateGlyph(int n) {
OpenGLTextGlyph &glyph = glyphs.insert(std::make_pair(n, OpenGLTextGlyph(n, font))).first->second;
OpenGLTextGlyph &glyph = glyphs.emplace(n, OpenGLTextGlyph(n, font)).first->second;
// Insert into some texture
for (auto& texture : textures) {

View file

@ -101,11 +101,11 @@ void init() {
auto hk_map = hotkey::inst->GetHotkeyMap();
for (auto const& hotkey : boost::make_iterator_range(hk_map.equal_range("edit/line/duplicate/shift"))) {
auto combo = agi::hotkey::Combo(hotkey.second.Context(), "edit/line/split/before", hotkey.second.Get());
hk_map.insert(std::make_pair(combo.CmdName(), combo));
hk_map.insert({combo.CmdName(), combo});
}
for (auto const& hotkey : boost::make_iterator_range(hk_map.equal_range("edit/line/duplicate/shift_back"))) {
auto combo = agi::hotkey::Combo(hotkey.second.Context(), "edit/line/split/after", hotkey.second.Get());
hk_map.insert(std::make_pair(combo.CmdName(), combo));
hk_map.insert({combo.CmdName(), combo});
}
hk_map.erase("edit/line/duplicate/shift");

View file

@ -195,9 +195,9 @@ public:
items.push_back(co->name());
if (flags != cmd::COMMAND_NORMAL)
dynamic_items.push_back(std::make_pair(co->name(), item));
dynamic_items.emplace_back(co->name(), item);
else
static_items.push_back(std::make_pair(co->name(), item));
static_items.emplace_back(co->name(), item);
return item->GetId();
}

View file

@ -47,9 +47,10 @@ SplineCurve::SplineCurve(Vector2D p1, Vector2D p2, Vector2D p3, Vector2D p4)
std::pair<SplineCurve, SplineCurve> SplineCurve::Split(float t) {
if (type == LINE) {
Vector2D m = p1 * (1 - t) + p2 * t;
return std::make_pair(
return {
SplineCurve(p1, m),
SplineCurve(m, p2));
SplineCurve(m, p2)
};
}
else if (type == BICUBIC) {
float u = 1 - t;
@ -60,11 +61,12 @@ std::pair<SplineCurve, SplineCurve> SplineCurve::Split(float t) {
Vector2D p234 = p23 * u + p34 * t;
Vector2D p1234 = p123 * u + p234 * t;
return std::make_pair(
return {
SplineCurve(p1, p12, p123, p1234),
SplineCurve(p1234, p234, p34, p4));
SplineCurve(p1234, p234, p34, p4)
};
}
return std::make_pair(SplineCurve(p1), SplineCurve(p1));
return {SplineCurve(p1), SplineCurve(p1)};
}
void SplineCurve::Smooth(Vector2D p0, Vector2D p5, float smooth) {

View file

@ -467,7 +467,7 @@ void SubsEditBox::CommitTimes(TimeField field) {
auto const& sel = c->selectionController->GetSelectedSet();
for (AssDialogue *d : sel) {
if (!initial_times.count(d))
initial_times[d] = std::make_pair(d->Start, d->End);
initial_times[d] = {d->Start, d->End};
switch (field) {
case TIME_START:

View file

@ -513,11 +513,11 @@ std::pair<int, int> SubsTextEditCtrl::GetBoundsOfWordAtPosition(int pos) {
for (auto const& tok : tokenized_line) {
if (len + (int)tok.length > pos) {
if (tok.type == agi::ass::DialogueTokenType::WORD)
return std::make_pair(len, tok.length);
return std::make_pair(0, 0);
return {len, tok.length};
return {0, 0};
}
len += tok.length;
}
return std::make_pair(0, 0);
return {0, 0};
}

View file

@ -179,7 +179,7 @@ void CleanCache(agi::fs::path const& directory, std::string const& file_type, ui
std::multimap<int64_t, agi::fs::path> cachefiles;
for (auto const& file : agi::fs::DirectoryIterator(directory, file_type)) {
agi::fs::path path = directory/file;
cachefiles.insert(std::make_pair(agi::fs::ModifiedTime(path), path));
cachefiles.insert({agi::fs::ModifiedTime(path), path});
total_size += agi::fs::Size(path);
}