diff --git a/cameraserver/src/main/native/cpp/cameraserver/CameraServerShared.cpp b/cameraserver/src/main/native/cpp/cameraserver/CameraServerShared.cpp index 4b6c9cf5af..0dc1388f00 100644 --- a/cameraserver/src/main/native/cpp/cameraserver/CameraServerShared.cpp +++ b/cameraserver/src/main/native/cpp/cameraserver/CameraServerShared.cpp @@ -22,7 +22,7 @@ class DefaultCameraServerShared : public frc::CameraServerShared { void ReportDriverStationErrorV(fmt::string_view format, fmt::format_args args) override {} std::pair GetRobotMainThreadId() const override { - return std::make_pair(std::thread::id(), false); + return std::pair{std::thread::id(), false}; } }; } // namespace diff --git a/cscore/src/main/native/cpp/Telemetry.cpp b/cscore/src/main/native/cpp/Telemetry.cpp index a3e8e5b714..e3e642e423 100644 --- a/cscore/src/main/native/cpp/Telemetry.cpp +++ b/cscore/src/main/native/cpp/Telemetry.cpp @@ -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(kind))); + auto it = m_user.find(std::pair{handle, static_cast(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(CS_SOURCE_BYTES_RECEIVED))] += + thr->m_current[std::pair{Handle{handleData.first, Handle::kSource}, + static_cast(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(CS_SOURCE_FRAMES_RECEIVED))] += + thr->m_current[std::pair{Handle{handleData.first, Handle::kSource}, + static_cast(CS_SOURCE_FRAMES_RECEIVED)}] += quantity; } diff --git a/cscore/src/main/native/cpp/UnlimitedHandleResource.h b/cscore/src/main/native/cpp/UnlimitedHandleResource.h index 18ddbd6bf0..a489878e2c 100644 --- a/cscore/src/main/native/cpp/UnlimitedHandleResource.h +++ b/cscore/src/main/native/cpp/UnlimitedHandleResource.h @@ -183,10 +183,10 @@ UnlimitedHandleResource::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 diff --git a/ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp b/ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp index 4d58d2ec4a..c075518776 100644 --- a/ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp +++ b/ntcore/src/main/native/cpp/jni/NetworkTablesJNI.cpp @@ -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); } diff --git a/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp b/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp index 815d516637..750e5520bc 100644 --- a/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp +++ b/ntcore/src/main/native/cpp/networktables/NetworkTable.cpp @@ -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)); }); } diff --git a/ntcore/src/main/native/cpp/ntcore_c.cpp b/ntcore/src/main/native/cpp/ntcore_c.cpp index a31b404e05..ff93c25062 100644 --- a/ntcore/src/main/native/cpp/ntcore_c.cpp +++ b/ntcore/src/main/native/cpp/ntcore_c.cpp @@ -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); } diff --git a/roborioteamnumbersetter/src/main/native/cpp/App.cpp b/roborioteamnumbersetter/src/main/native/cpp/App.cpp index 4394b3d841..7e66467620 100644 --- a/roborioteamnumbersetter/src/main/native/cpp/App.cpp +++ b/roborioteamnumbersetter/src/main/native/cpp/App.cpp @@ -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); diff --git a/wpilibNewCommands/src/test/native/cpp/frc2/command/SelectCommandTest.cpp b/wpilibNewCommands/src/test/native/cpp/frc2/command/SelectCommandTest.cpp index eb05034da2..dc882a0ed1 100644 --- a/wpilibNewCommands/src/test/native/cpp/frc2/command/SelectCommandTest.cpp +++ b/wpilibNewCommands/src/test/native/cpp/frc2/command/SelectCommandTest.cpp @@ -68,7 +68,7 @@ class TestableSelectCommand : public SelectCommand { std::vector>> 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; diff --git a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardContainer.cpp b/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardContainer.cpp index b8f4ccae34..2b25ef8103 100644 --- a/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardContainer.cpp +++ b/wpilibc/src/main/native/cpp/shuffleboard/ShuffleboardContainer.cpp @@ -50,7 +50,7 @@ ShuffleboardLayout& ShuffleboardContainer::GetLayout(std::string_view title, auto layout = std::make_unique(*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]; } diff --git a/wpilibc/src/main/native/cppcs/RobotBase.cpp b/wpilibc/src/main/native/cppcs/RobotBase.cpp index 04af2fe3a4..7b413b8614 100644 --- a/wpilibc/src/main/native/cppcs/RobotBase.cpp +++ b/wpilibc/src/main/native/cppcs/RobotBase.cpp @@ -83,7 +83,7 @@ class WPILibCameraServerShared : public frc::CameraServerShared { ReportErrorV(err::Error, __FILE__, __LINE__, __FUNCTION__, format, args); } std::pair GetRobotMainThreadId() const override { - return std::make_pair(RobotBase::GetThreadId(), true); + return std::pair{RobotBase::GetThreadId(), true}; } }; class WPILibMathShared : public wpi::math::MathShared { diff --git a/wpinet/src/main/native/cpp/HttpUtil.cpp b/wpinet/src/main/native/cpp/HttpUtil.cpp index c17f68288f..92022ee797 100644 --- a/wpinet/src/main/native/cpp/HttpUtil.cpp +++ b/wpinet/src/main/native/cpp/HttpUtil.cpp @@ -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; diff --git a/wpinet/src/main/native/include/wpinet/HttpUtil.h b/wpinet/src/main/native/include/wpinet/HttpUtil.h index 32edda6fe1..1509a6f1a0 100644 --- a/wpinet/src/main/native/include/wpinet/HttpUtil.h +++ b/wpinet/src/main/native/include/wpinet/HttpUtil.h @@ -320,10 +320,10 @@ class HttpRequest { : host{loc.host}, port{loc.port} { SmallVector, 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); diff --git a/wpinet/src/main/native/include/wpinet/uv/Loop.h b/wpinet/src/main/native/include/wpinet/uv/Loop.h index 2c885d3c24..275bdf1d4f 100644 --- a/wpinet/src/main/native/include/wpinet/uv/Loop.h +++ b/wpinet/src/main/native/include/wpinet/uv/Loop.h @@ -152,7 +152,7 @@ class Loop final : public std::enable_shared_from_this { */ std::pair 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}}; } /** diff --git a/wpinet/src/main/native/include/wpinet/uv/Tty.h b/wpinet/src/main/native/include/wpinet/uv/Tty.h index 2dd4f97822..647f4b587c 100644 --- a/wpinet/src/main/native/include/wpinet/uv/Tty.h +++ b/wpinet/src/main/native/include/wpinet/uv/Tty.h @@ -76,7 +76,7 @@ class Tty final : public StreamImpl { std::pair 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}; } }; diff --git a/wpinet/src/test/native/cpp/MulticastTest.cpp b/wpinet/src/test/native/cpp/MulticastTest.cpp index 412dd4841b..b05d7bbb1e 100644 --- a/wpinet/src/test/native/cpp/MulticastTest.cpp +++ b/wpinet/src/test/native/cpp/MulticastTest.cpp @@ -38,7 +38,7 @@ TEST(MulticastServiceAnnouncerTest, SingleText) { const std::string_view serviceType = "_wpitxt"; const int port = std::rand(); std::array, 1> txt = { - std::make_pair("hello", "world")}; + std::pair{"hello", "world"}}; wpi::MulticastServiceAnnouncer announcer(serviceName, serviceType, port, txt); wpi::MulticastServiceResolver resolver(serviceType); diff --git a/wpiutil/src/main/native/include/wpi/ct_map.h b/wpiutil/src/main/native/include/wpi/ct_map.h new file mode 100644 index 0000000000..8456f46bb5 --- /dev/null +++ b/wpiutil/src/main/native/include/wpi/ct_map.h @@ -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 +#include +#include +#include +#include + +namespace wpi { + +template +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, Size> data; +}; + +} // namespace wpi diff --git a/wpiutil/src/main/native/include/wpi/interpolating_map.h b/wpiutil/src/main/native/include/wpi/interpolating_map.h index 5eff514c19..d334cd8026 100644 --- a/wpiutil/src/main/native/include/wpi/interpolating_map.h +++ b/wpiutil/src/main/native/include/wpi/interpolating_map.h @@ -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}); } /** diff --git a/wpiutil/src/test/native/cpp/StringMapTest.cpp b/wpiutil/src/test/native/cpp/StringMapTest.cpp index 04dffc503f..0086660923 100644 --- a/wpiutil/src/test/native/cpp/StringMapTest.cpp +++ b/wpiutil/src/test/native/cpp/StringMapTest.cpp @@ -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::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::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 t; - t.insert(std::make_pair("Test", StringMapTestStruct(123))); + t.insert(std::pair{"Test", StringMapTestStruct(123)}); StringMap::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 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 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);