Replace std::make_pair with std::pair CTAD (#7405)

This commit is contained in:
Tyler Veness
2024-11-17 20:29:23 -08:00
committed by GitHub
parent b4bec566f0
commit a04c40f589
18 changed files with 64 additions and 30 deletions

View File

@@ -22,7 +22,7 @@ class DefaultCameraServerShared : public frc::CameraServerShared {
void ReportDriverStationErrorV(fmt::string_view format,
fmt::format_args args) override {}
std::pair<std::thread::id, bool> GetRobotMainThreadId() const override {
return std::make_pair(std::thread::id(), false);
return std::pair{std::thread::id(), false};
}
};
} // namespace

View File

@@ -34,7 +34,7 @@ class Telemetry::Thread : public wpi::SafeThread {
int64_t Telemetry::Thread::GetValue(CS_Handle handle, CS_TelemetryKind kind,
CS_Status* status) {
auto it = m_user.find(std::make_pair(handle, static_cast<int>(kind)));
auto it = m_user.find(std::pair{handle, static_cast<int>(kind)});
if (it == m_user.end()) {
*status = CS_EMPTY_VALUE;
return 0;
@@ -136,8 +136,8 @@ void Telemetry::RecordSourceBytes(const SourceImpl& source, int quantity) {
return;
}
auto handleData = Instance::GetInstance().FindSource(source);
thr->m_current[std::make_pair(Handle{handleData.first, Handle::kSource},
static_cast<int>(CS_SOURCE_BYTES_RECEIVED))] +=
thr->m_current[std::pair{Handle{handleData.first, Handle::kSource},
static_cast<int>(CS_SOURCE_BYTES_RECEIVED)}] +=
quantity;
}
@@ -147,7 +147,7 @@ void Telemetry::RecordSourceFrames(const SourceImpl& source, int quantity) {
return;
}
auto handleData = Instance::GetInstance().FindSource(source);
thr->m_current[std::make_pair(Handle{handleData.first, Handle::kSource},
static_cast<int>(CS_SOURCE_FRAMES_RECEIVED))] +=
thr->m_current[std::pair{Handle{handleData.first, Handle::kSource},
static_cast<int>(CS_SOURCE_FRAMES_RECEIVED)}] +=
quantity;
}

View File

@@ -183,10 +183,10 @@ UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::FindIf(F func) {
for (size_t i = 0; i < m_structures.size(); i++) {
auto& structure = m_structures[i];
if (structure != nullptr && func(*structure)) {
return std::make_pair(MakeHandle(i), structure);
return std::pair{MakeHandle(i), structure};
}
}
return std::make_pair(0, nullptr);
return std::pair{0, nullptr};
}
} // namespace cs

View File

@@ -1305,7 +1305,7 @@ Java_edu_wpi_first_networktables_NetworkTablesJNI_setServer__I_3Ljava_lang_Strin
}
names.emplace_back(JStringRef{env, elem}.str());
servers.emplace_back(
std::make_pair(std::string_view{names.back()}, portInts[i]));
std::pair{std::string_view{names.back()}, portInts[i]});
}
nt::SetServer(inst, servers);
}

View File

@@ -425,7 +425,7 @@ NT_Listener NetworkTable::AddSubTableListener(SubTableListener listener) {
if (notified_tables->find(sub_table_key) != notified_tables->end()) {
return;
}
notified_tables->insert(std::make_pair(sub_table_key, '\0'));
notified_tables->insert(std::pair{sub_table_key, '\0'});
cb(this, sub_table_key, this->GetSubTable(sub_table_key));
});
}

View File

@@ -561,7 +561,7 @@ void NT_SetServerMulti(NT_Inst inst, size_t count,
servers.reserve(count);
for (size_t i = 0; i < count; ++i) {
servers.emplace_back(
std::make_pair(wpi::to_string_view(&server_names[i]), ports[i]));
std::pair{wpi::to_string_view(&server_names[i]), ports[i]});
}
nt::SetServer(inst, servers);
}

View File

@@ -81,7 +81,7 @@ static void FindDevices() {
if (macKey != data.txt.end()) {
auto& mac = macKey->second;
auto& foundDevice = foundDevices[mac];
foundDevice = std::make_pair(data.ipv4Address, data.hostName);
foundDevice = std::pair{data.ipv4Address, data.hostName};
auto& deviceStatus = deviceStatuses[mac];
if (!deviceStatus) {
deploySession.GetStatus(mac, foundDevice.first);

View File

@@ -68,7 +68,7 @@ class TestableSelectCommand : public SelectCommand<int> {
std::vector<std::pair<int, std::unique_ptr<Command>>> vec;
int index = 0;
for (auto&& command : commands) {
vec.emplace_back(std::make_pair(index, std::move(command)));
vec.emplace_back(std::pair{index, std::move(command)});
index++;
}
return vec;

View File

@@ -50,7 +50,7 @@ ShuffleboardLayout& ShuffleboardContainer::GetLayout(std::string_view title,
auto layout = std::make_unique<ShuffleboardLayout>(*this, title, type);
auto ptr = layout.get();
m_components.emplace_back(std::move(layout));
m_layouts.insert(std::make_pair(title, ptr));
m_layouts.insert(std::pair{title, ptr});
}
return *m_layouts[title];
}

View File

@@ -83,7 +83,7 @@ class WPILibCameraServerShared : public frc::CameraServerShared {
ReportErrorV(err::Error, __FILE__, __LINE__, __FUNCTION__, format, args);
}
std::pair<std::thread::id, bool> GetRobotMainThreadId() const override {
return std::make_pair(RobotBase::GetThreadId(), true);
return std::pair{RobotBase::GetThreadId(), true};
}
};
class WPILibMathShared : public wpi::math::MathShared {

View File

@@ -354,7 +354,7 @@ HttpLocation::HttpLocation(std::string_view url_, bool* error,
return;
}
params.emplace_back(std::make_pair(param, value));
params.emplace_back(std::pair{param, value});
}
*error = false;

View File

@@ -320,10 +320,10 @@ class HttpRequest {
: host{loc.host}, port{loc.port} {
SmallVector<std::pair<std::string_view, std::string_view>, 4> params;
for (const auto& p : loc.params) {
params.emplace_back(std::make_pair(GetFirst(p), GetSecond(p)));
params.emplace_back(std::pair{GetFirst(p), GetSecond(p)});
}
for (const auto& p : extraParams) {
params.emplace_back(std::make_pair(GetFirst(p), GetSecond(p)));
params.emplace_back(std::pair{GetFirst(p), GetSecond(p)});
}
SetPath(loc.path, params);
SetAuth(loc);

View File

@@ -152,7 +152,7 @@ class Loop final : public std::enable_shared_from_this<Loop> {
*/
std::pair<bool, Time> GetTimeout() const noexcept {
auto to = uv_backend_timeout(m_loop);
return std::make_pair(to == -1, Time{to});
return std::pair{to == -1, Time{to}};
}
/**

View File

@@ -76,7 +76,7 @@ class Tty final : public StreamImpl<Tty, uv_tty_t> {
std::pair<int, int> GetWindowSize() {
int width = 0, height = 0;
Invoke(&uv_tty_get_winsize, GetRaw(), &width, &height);
return std::make_pair(width, height);
return std::pair{width, height};
}
};

View File

@@ -38,7 +38,7 @@ TEST(MulticastServiceAnnouncerTest, SingleText) {
const std::string_view serviceType = "_wpitxt";
const int port = std::rand();
std::array<std::pair<std::string, std::string>, 1> txt = {
std::make_pair("hello", "world")};
std::pair{"hello", "world"}};
wpi::MulticastServiceAnnouncer announcer(serviceName, serviceType, port, txt);
wpi::MulticastServiceResolver resolver(serviceType);

View File

@@ -0,0 +1,35 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <algorithm>
#include <array>
#include <cstddef>
#include <stdexcept>
#include <utility>
namespace wpi {
template <typename Key, typename Value, size_t Size>
class ct_map {
constexpr ct_map();
[[nodiscard]]
constexpr const Value& operator[](const Key& key) const {
if (const auto it =
std::find_if(data.begin(), data.end(),
[&key](const auto& v) { return v.first == key; });
it != data.end()) {
return it->second;
} else {
throw std::range_error("Not found");
}
}
private:
std::array<std::pair<Key, Value>, Size> data;
};
} // namespace wpi

View File

@@ -29,7 +29,7 @@ class interpolating_map {
* @param value The value.
*/
void insert(const Key& key, const Value& value) {
m_container.insert(std::make_pair(key, value));
m_container.insert(std::pair{key, value});
}
/**
@@ -39,7 +39,7 @@ class interpolating_map {
* @param value The value.
*/
void insert(Key&& key, Value&& value) {
m_container.insert(std::make_pair(key, value));
m_container.insert(std::pair{key, value});
}
/**

View File

@@ -250,8 +250,7 @@ TEST_F(StringMapTest, Iteration) {
// Test insert() method.
TEST_F(StringMapTest, Insert) {
SCOPED_TRACE("InsertTest");
testMap.insert(
std::make_pair(std::string_view(testKeyFirst, testKeyLength), 1u));
testMap.insert(std::pair{std::string_view(testKeyFirst, testKeyLength), 1u});
assertSingleItemMap();
}
@@ -260,7 +259,7 @@ TEST_F(StringMapTest, InsertPair) {
bool Inserted;
StringMap<uint32_t>::iterator NewIt;
std::tie(NewIt, Inserted) =
testMap.insert(std::make_pair(testKeyFirst, testValue));
testMap.insert(std::pair{testKeyFirst, testValue});
EXPECT_EQ(1u, testMap.size());
EXPECT_EQ(testValue, testMap[testKeyFirst]);
EXPECT_EQ(testKeyFirst, NewIt->first);
@@ -269,7 +268,7 @@ TEST_F(StringMapTest, InsertPair) {
StringMap<uint32_t>::iterator ExistingIt;
std::tie(ExistingIt, Inserted) =
testMap.insert(std::make_pair(testKeyFirst, testValue + 1));
testMap.insert(std::pair{testKeyFirst, testValue + 1});
EXPECT_EQ(1u, testMap.size());
EXPECT_EQ(testValue, testMap[testKeyFirst]);
EXPECT_FALSE(Inserted);
@@ -306,7 +305,7 @@ struct StringMapTestStruct {
TEST_F(StringMapTest, NonDefaultConstructable) {
StringMap<StringMapTestStruct> t;
t.insert(std::make_pair("Test", StringMapTestStruct(123)));
t.insert(std::pair{"Test", StringMapTestStruct(123)});
StringMap<StringMapTestStruct>::iterator iter = t.find("Test");
ASSERT_NE(iter, t.end());
ASSERT_EQ(iter->second.i, 123);
@@ -443,7 +442,7 @@ struct Countable {
TEST_F(StringMapTest, MoveDtor) {
int InstanceCount = 0;
StringMap<Countable> A;
A.insert(std::make_pair("x", Countable(42, InstanceCount)));
A.insert(std::pair{"x", Countable(42, InstanceCount)});
ASSERT_EQ(InstanceCount, 1);
auto I = A.find("x");
ASSERT_NE(I, A.end());
@@ -474,7 +473,7 @@ TEST_F(StringMapTest, StructuredBindings) {
TEST_F(StringMapTest, StructuredBindingsMoveOnly) {
StringMap<MoveOnly> A;
A.insert(std::make_pair("a", MoveOnly(42)));
A.insert(std::pair{"a", MoveOnly(42)});
for (auto&& [Key, Value] : A) {
EXPECT_EQ("a", Key);