From a00ebc65af5f365ed2cbddbc10fe27d23b2d5c76 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Wed, 4 Aug 2021 21:19:38 -0700 Subject: [PATCH] remove make_pair There are better alternatives with C++11. Signed-off-by: Rosen Penev --- src/ast.cpp | 16 ++++++++-------- src/complete.cpp | 2 +- src/env.cpp | 4 ++-- src/highlight.cpp | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/ast.cpp b/src/ast.cpp index f614c0cc2..e7d7e3853 100644 --- a/src/ast.cpp +++ b/src/ast.cpp @@ -232,33 +232,33 @@ static std::pair find_block_open_keyword(const break; case type_t::for_header: { const auto *h = cursor->as(); - return std::make_pair(h->kw_for.range, L"for loop"); + return {h->kw_for.range, L"for loop"}; } case type_t::while_header: { const auto *h = cursor->as(); - return std::make_pair(h->kw_while.range, L"while loop"); + return {h->kw_while.range, L"while loop"}; } case type_t::function_header: { const auto *h = cursor->as(); - return std::make_pair(h->kw_function.range, L"function definition"); + return {h->kw_function.range, L"function definition"}; } case type_t::begin_header: { const auto *h = cursor->as(); - return std::make_pair(h->kw_begin.range, L"begin"); + return {h->kw_begin.range, L"begin"}; } case type_t::if_statement: { const auto *h = cursor->as(); - return std::make_pair(h->if_clause.kw_if.range, L"if statement"); + return {h->if_clause.kw_if.range, L"if statement"}; } case type_t::switch_statement: { const auto *h = cursor->as(); - return std::make_pair(h->kw_switch.range, L"switch statement"); + return {h->kw_switch.range, L"switch statement"}; } default: - return std::make_pair(source_range_t{}, nullptr); + return {source_range_t{}, nullptr}; } } - return std::make_pair(source_range_t{}, nullptr); + return {source_range_t{}, nullptr}; } /// \return the decoration for this statement. diff --git a/src/complete.cpp b/src/complete.cpp index 6ff6086ab..2b2678891 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -701,7 +701,7 @@ void completer_t::complete_cmd_desc(const wcstring &str) { // And once again I make sure the first character is uppercased because I like it that // way, and I get to decide these things. val.at(0) = towupper(val.at(0)); - lookup.insert(std::make_pair(std::move(key), std::move(val))); + lookup.emplace(std::move(key), std::move(val)); } // Then do a lookup on every completion and if a match is found, change to the new diff --git a/src/env.cpp b/src/env.cpp index 0d2625007..981b8dea3 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -682,9 +682,9 @@ std::shared_ptr env_scoped_impl_t::create_export assert(var && "Variable should be present in uvars"); // Note that std::map::insert does NOT overwrite a value already in the map, // which we depend on here. - // Note: Using std::move around make_pair prevents the compiler from implementing + // Note: Using std::move around emplace prevents the compiler from implementing // copy elision. - vals.insert(std::make_pair(key, std::move(*var))); + vals.emplace(key, std::move(*var)); } // Dorky way to add our single exported computed variable. diff --git a/src/highlight.cpp b/src/highlight.cpp index 1650d82c9..ff33c79a6 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -387,7 +387,7 @@ rgb_color_t highlight_color_resolver_t::resolve_spec(const highlight_spec_t &hig bool is_background, const environment_t &vars) { auto &cache = is_background ? bg_cache_ : fg_cache_; - auto p = cache.insert(std::make_pair(highlight, rgb_color_t{})); + auto p = cache.emplace(highlight, rgb_color_t{}); auto iter = p.first; bool did_insert = p.second; if (did_insert) {