mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
Replace std::make_pair with std::pair CTAD (#7405)
This commit is contained in:
35
wpiutil/src/main/native/include/wpi/ct_map.h
Normal file
35
wpiutil/src/main/native/include/wpi/ct_map.h
Normal 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
|
||||
@@ -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});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user