Use std::optional instead of mbgl::optional (#911)

This commit is contained in:
Bart Louwers
2023-03-17 12:51:59 +01:00
committed by GitHub
parent 36846439c6
commit 15ad65dd3d
482 changed files with 2605 additions and 2652 deletions

View File

@@ -33,7 +33,7 @@ StubFileSource::StubFileSource(const ResourceOptions& resourceOptions_, const Cl
// Explicit copy to avoid iterator invalidation if ~StubFileRequest gets called within the loop.
auto pending_ = pending;
for (auto& pair : pending_) {
optional<Response> res = std::get<1>(pair.second)(std::get<0>(pair.second));
std::optional<Response> res = std::get<1>(pair.second)(std::get<0>(pair.second));
if (res) {
// This must be before calling the callback, because it's possible that the callback
// could:
@@ -58,7 +58,7 @@ StubFileSource::~StubFileSource() = default;
std::unique_ptr<AsyncRequest> StubFileSource::request(const Resource& resource, Callback callback) {
auto req = std::make_unique<StubFileRequest>(*this);
if (type == ResponseType::Synchronous) {
optional<Response> res = response(resource);
std::optional<Response> res = response(resource);
if (res) {
callback(*res);
}
@@ -84,7 +84,7 @@ mapbox::base::Value StubFileSource::getProperty(const std::string& key) const {
return (it != properties.end()) ? it->second : mapbox::base::Value();
}
optional<Response> StubFileSource::defaultResponse(const Resource& resource) {
std::optional<Response> StubFileSource::defaultResponse(const Resource& resource) {
switch (resource.kind) {
case Resource::Kind::Style:
if (!styleResponse) throw std::runtime_error("unexpected style request");

View File

@@ -29,7 +29,7 @@ public:
void setProperty(const std::string&, const mapbox::base::Value&) override;
mapbox::base::Value getProperty(const std::string&) const override;
using ResponseFunction = std::function<optional<Response> (const Resource&)>;
using ResponseFunction = std::function<std::optional<Response> (const Resource&)>;
// You can set the response callback on a global level by assigning this callback:
ResponseFunction response = [this] (const Resource& resource) {
@@ -55,7 +55,7 @@ private:
friend class StubOnlineFileSource;
// The default behavior is to throw if no per-kind callback has been set.
optional<Response> defaultResponse(const Resource&);
std::optional<Response> defaultResponse(const Resource&);
std::unordered_map<AsyncRequest*, std::tuple<Resource, ResponseFunction, Callback>> pending;
ResponseType type;

View File

@@ -32,8 +32,8 @@ public:
return id;
}
optional<Value> getValue(const std::string& key) const override {
return properties.count(key) ? properties.at(key) : optional<Value>();
std::optional<Value> getValue(const std::string& key) const override {
return properties.count(key) ? properties.at(key) : std::optional<Value>();
}
const GeometryCollection& getGeometries() const override {

View File

@@ -34,8 +34,7 @@ void checkImage(const std::string& base,
try {
expected_image = util::read_file(base + "/expected.png");
} catch (std::exception& ex) {
Log::Error(Event::Setup, "Failed to load expected image %s: %s",
(base + "/expected.png").c_str(), ex.what());
Log::Error(Event::Setup, "Failed to load expected image " + base + "/expected.png" + ": " + ex.what());
throw;
}