Skip to content

Commit 01fdd7f

Browse files
mpimenovmaksimandrianov
authored andcommitted
[omim] Replaced boost::optional with std::optional.
Since C++17, optional is part of the C++ Standard Library.
1 parent f5de0be commit 01fdd7f

File tree

114 files changed

+406
-470
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+406
-470
lines changed

3party/jansson/myjansson.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77

88
#include <cstdint>
99
#include <memory>
10+
#include <optional>
1011
#include <string>
1112
#include <vector>
1213

13-
#include <boost/optional.hpp>
14-
1514
#include "3party/jansson/src/jansson.h"
1615

1716
namespace base
@@ -163,13 +162,13 @@ void FromJSONObject(json_t * root, std::string const & field, T & result)
163162
}
164163

165164
template <typename T>
166-
boost::optional<T> FromJSONObjectOptional(json_t const * root, char const * field)
165+
std::optional<T> FromJSONObjectOptional(json_t const * root, char const * field)
167166
{
168167
auto * json = base::GetJSONOptionalField(root, field);
169168
if (!json)
170169
return {};
171170

172-
boost::optional<T> result{T{}};
171+
std::optional<T> result{T{}};
173172
FromJSON(json, *result);
174173
return result;
175174
}

android/jni/com/mapswithme/maps/Framework.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,7 +2000,7 @@ Java_com_mapswithme_maps_Framework_nativeHasMegafonCategoryBanner(JNIEnv * env,
20002000
if (!position)
20012001
return static_cast<jboolean>(false);
20022002

2003-
auto const latLon = mercator::ToLatLon(position.get());
2003+
auto const latLon = mercator::ToLatLon(*position);
20042004
return static_cast<jboolean>(ads::HasMegafonCategoryBanner(frm()->GetStorage(),
20052005
frm()->GetTopmostCountries(latLon),
20062006
languages::GetCurrentNorm()));
@@ -2111,7 +2111,9 @@ Java_com_mapswithme_maps_Framework_nativeGetCurrentTipIndex(JNIEnv * env, jclass
21112111
{
21122112
auto const & tipsApi = frm()->GetTipsApi();
21132113
auto const tip = tipsApi.GetTip();
2114-
return tip.is_initialized() ? static_cast<jint>(tip.get()) : kUndefinedTip;
2114+
if (!tip)
2115+
return kUndefinedTip;
2116+
return static_cast<jint>(*tip);
21152117
}
21162118

21172119
JNIEXPORT void JNICALL

android/jni/com/mapswithme/maps/LightFramework.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Java_com_mapswithme_maps_LightFramework_nativeGetNotification(JNIEnv * env, jcla
101101
if (!notification)
102102
return nullptr;
103103

104-
auto const & n = notification.get();
104+
auto const & n = *notification;
105105
// Type::UgcReview is only supported.
106106
CHECK_EQUAL(n.GetType(), notifications::NotificationCandidate::Type::UgcReview, ());
107107

android/jni/com/mapswithme/maps/UserMarkHelper.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,8 @@ jobject CreateHotelType(JNIEnv * env, place_page::Info const & info)
6262
static jmethodID const hotelTypeCtorId =
6363
jni::GetConstructorID(env, hotelTypeClass, "(ILjava/lang/String;)V");
6464

65-
auto const tag = ftypes::IsHotelChecker::GetHotelTypeTag(info.GetHotelType().get());
66-
return env->NewObject(hotelTypeClass, hotelTypeCtorId,
67-
static_cast<jint>(info.GetHotelType().get()),
65+
auto const tag = ftypes::IsHotelChecker::GetHotelTypeTag(*info.GetHotelType());
66+
return env->NewObject(hotelTypeClass, hotelTypeCtorId, static_cast<jint>(*info.GetHotelType()),
6867
jni::ToJavaString(env, tag));
6968
}
7069

@@ -148,7 +147,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
148147
jni::TScopedLocalRef hotelType(env, CreateHotelType(env, info));
149148
jni::TScopedLocalRef popularity(env, CreatePopularity(env, info));
150149

151-
int priceRate = info.GetRawApproximatePricing().get_value_or(kPriceRateUndefined);
150+
int priceRate = info.GetRawApproximatePricing().value_or(kPriceRateUndefined);
152151

153152
if (info.IsBookmark())
154153
{

base/cancellable.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
#include <atomic>
44
#include <chrono>
55
#include <mutex>
6+
#include <optional>
67
#include <string>
78

8-
#include <boost/optional.hpp>
9-
109
namespace base
1110
{
1211
// This is a helper thread-safe class which can be mixed in
@@ -51,7 +50,7 @@ class Cancellable
5150

5251
mutable Status m_status = Status::Active;
5352

54-
boost::optional<std::chrono::steady_clock::time_point> m_deadline;
53+
std::optional<std::chrono::steady_clock::time_point> m_deadline;
5554
};
5655

5756
std::string DebugPrint(Cancellable::Status status);

coding/csv_reader.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ CSVReader::Rows CSVReader::ReadAll()
4646
return file;
4747
}
4848

49-
boost::optional<CSVReader::Row> CSVReader::ReadRow()
49+
std::optional<CSVReader::Row> CSVReader::ReadRow()
5050
{
5151
auto const line = m_reader->ReadLine();
5252
if (!line)
@@ -62,15 +62,15 @@ size_t CSVReader::GetCurrentLineNumber() const { return m_currentLine; }
6262

6363
CSVReader::IstreamWrapper::IstreamWrapper(std::istream & stream) : m_stream(stream) {}
6464

65-
boost::optional<std::string> CSVReader::IstreamWrapper::ReadLine()
65+
std::optional<std::string> CSVReader::IstreamWrapper::ReadLine()
6666
{
6767
std::string line;
68-
return std::getline(m_stream, line) ? line : boost::optional<std::string>();
68+
return std::getline(m_stream, line) ? line : std::optional<std::string>();
6969
}
7070

7171
CSVReader::ReaderWrapper::ReaderWrapper(Reader const & reader) : m_reader(reader) {}
7272

73-
boost::optional<std::string> CSVReader::ReaderWrapper::ReadLine()
73+
std::optional<std::string> CSVReader::ReaderWrapper::ReadLine()
7474
{
7575
std::vector<char> line;
7676
char ch = '\0';
@@ -98,7 +98,7 @@ CSVReader::DefaultReader::DefaultReader(std::string const & filename)
9898
m_stream.exceptions(std::ios::badbit);
9999
}
100100

101-
boost::optional<std::string> CSVReader::DefaultReader::ReadLine()
101+
std::optional<std::string> CSVReader::DefaultReader::ReadLine()
102102
{
103103
return IstreamWrapper(m_stream).ReadLine();
104104
}

coding/csv_reader.hpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44

55
#include <fstream>
66
#include <functional>
7+
#include <optional>
78
#include <sstream>
89
#include <string>
910
#include <vector>
1011

11-
#include <boost/optional.hpp>
12-
1312
namespace coding
1413
{
1514
class CSVReader
@@ -26,7 +25,7 @@ class CSVReader
2625
char GetDelimiter() const;
2726

2827
Row const & GetHeader() const;
29-
boost::optional<Row> ReadRow();
28+
std::optional<Row> ReadRow();
3029
Rows ReadAll();
3130

3231
template <typename Fn>
@@ -45,7 +44,7 @@ class CSVReader
4544
public:
4645
virtual ~ReaderInterface() = default;
4746

48-
virtual boost::optional<std::string> ReadLine() = 0;
47+
virtual std::optional<std::string> ReadLine() = 0;
4948
};
5049

5150
class IstreamWrapper : public ReaderInterface
@@ -54,7 +53,7 @@ class CSVReader
5453
explicit IstreamWrapper(std::istream & stream);
5554

5655
// ReaderInterface overrides:
57-
boost::optional<std::string> ReadLine() override;
56+
std::optional<std::string> ReadLine() override;
5857

5958
private:
6059
std::istream & m_stream;
@@ -66,7 +65,7 @@ class CSVReader
6665
explicit ReaderWrapper(Reader const & reader);
6766

6867
// ReaderInterface overrides:
69-
boost::optional<std::string> ReadLine() override;
68+
std::optional<std::string> ReadLine() override;
7069

7170
private:
7271
size_t m_pos = 0;
@@ -79,7 +78,7 @@ class CSVReader
7978
explicit DefaultReader(std::string const & filename);
8079

8180
// ReaderInterface overrides:
82-
boost::optional<std::string> ReadLine() override;
81+
std::optional<std::string> ReadLine() override;
8382

8483
private:
8584
std::ifstream m_stream;
@@ -114,7 +113,7 @@ class CSVRunner
114113

115114
private:
116115
CSVReader & m_reader;
117-
boost::optional<CSVReader::Row> m_current;
116+
std::optional<CSVReader::Row> m_current;
118117
};
119118

120119
// Warning: It reads first line.

drape/vulkan/vulkan_base_context.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ void VulkanBaseContext::ApplyFramebuffer(std::string const & framebufferLabel)
348348

349349
if (m_currentFramebuffer == nullptr)
350350
{
351-
colorFormat = m_surfaceFormat.get().format;
351+
colorFormat = m_surfaceFormat->format;
352352
depthFormat = VulkanFormatUnpacker::Unpack(TextureFormat::Depth);
353353

354354
fbData.m_packedAttachmentOperations = packedAttachmentOperations;
@@ -766,19 +766,19 @@ ref_ptr<VulkanStagingBuffer> VulkanBaseContext::GetDefaultStagingBuffer() const
766766

767767
void VulkanBaseContext::RecreateSwapchain()
768768
{
769-
CHECK(m_surface.is_initialized(), ());
770-
CHECK(m_surfaceFormat.is_initialized(), ());
769+
CHECK(m_surface.has_value(), ());
770+
CHECK(m_surfaceFormat.has_value(), ());
771771

772772
DestroySwapchain();
773773

774774
VkSwapchainCreateInfoKHR swapchainCI = {};
775775
swapchainCI.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
776776
swapchainCI.pNext = nullptr;
777-
swapchainCI.surface = m_surface.get();
777+
swapchainCI.surface = *m_surface;
778778
swapchainCI.minImageCount = std::min(m_surfaceCapabilities.minImageCount + 1,
779779
m_surfaceCapabilities.maxImageCount);
780-
swapchainCI.imageFormat = m_surfaceFormat.get().format;
781-
swapchainCI.imageColorSpace = m_surfaceFormat.get().colorSpace;
780+
swapchainCI.imageFormat = m_surfaceFormat->format;
781+
swapchainCI.imageColorSpace = m_surfaceFormat->colorSpace;
782782
swapchainCI.imageExtent = m_surfaceCapabilities.currentExtent;
783783

784784
swapchainCI.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
@@ -819,7 +819,7 @@ void VulkanBaseContext::RecreateSwapchain()
819819
swapchainImageViewCI.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
820820
swapchainImageViewCI.image = m_swapchainImages[i];
821821
swapchainImageViewCI.viewType = VK_IMAGE_VIEW_TYPE_2D;
822-
swapchainImageViewCI.format = m_surfaceFormat.get().format;
822+
swapchainImageViewCI.format = m_surfaceFormat->format;
823823
swapchainImageViewCI.components = {VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G,
824824
VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A};
825825
swapchainImageViewCI.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;

drape/vulkan/vulkan_base_context.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
#include <vulkan_wrapper.h>
1616
#include <vulkan/vulkan.h>
1717

18-
#include <boost/optional.hpp>
19-
2018
#include <array>
2119
#include <atomic>
2220
#include <cstdint>
2321
#include <functional>
2422
#include <map>
23+
#include <optional>
2524
#include <vector>
2625

2726
namespace dp
@@ -184,10 +183,10 @@ class VulkanBaseContext : public dp::GraphicsContext
184183

185184
ref_ptr<VulkanObjectManager> m_objectManager;
186185
drape_ptr<VulkanPipeline> m_pipeline;
187-
boost::optional<VkSurfaceKHR> m_surface;
186+
std::optional<VkSurfaceKHR> m_surface;
188187

189188
VkSurfaceCapabilitiesKHR m_surfaceCapabilities;
190-
boost::optional<VkSurfaceFormatKHR> m_surfaceFormat;
189+
std::optional<VkSurfaceFormatKHR> m_surfaceFormat;
191190

192191
VkSwapchainKHR m_swapchain = {};
193192
std::vector<VkImageView> m_swapchainImageViews;

drape/vulkan/vulkan_memory_manager.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ std::array<uint32_t, VulkanMemoryManager::kResourcesCount> const kDesiredSizeInB
3030
100 * 1024 * 1024, // Image
3131
}};
3232

33-
VkMemoryPropertyFlags GetMemoryPropertyFlags(VulkanMemoryManager::ResourceType resourceType,
34-
boost::optional<VkMemoryPropertyFlags> & fallbackTypeBits)
33+
VkMemoryPropertyFlags GetMemoryPropertyFlags(
34+
VulkanMemoryManager::ResourceType resourceType,
35+
std::optional<VkMemoryPropertyFlags> & fallbackTypeBits)
3536
{
3637
switch (resourceType)
3738
{
@@ -93,8 +94,8 @@ VulkanMemoryManager::~VulkanMemoryManager()
9394
ASSERT_EQUAL(m_totalAllocationCounter, 0, ());
9495
}
9596

96-
boost::optional<uint32_t> VulkanMemoryManager::GetMemoryTypeIndex(uint32_t typeBits,
97-
VkMemoryPropertyFlags properties) const
97+
std::optional<uint32_t> VulkanMemoryManager::GetMemoryTypeIndex(
98+
uint32_t typeBits, VkMemoryPropertyFlags properties) const
9899
{
99100
for (uint32_t i = 0; i < m_memoryProperties.memoryTypeCount; i++)
100101
{
@@ -189,12 +190,12 @@ VulkanMemoryManager::AllocationPtr VulkanMemoryManager::Allocate(ResourceType re
189190
}
190191

191192
// Looking for memory index by memory properties.
192-
boost::optional<VkMemoryPropertyFlags> fallbackFlags;
193+
std::optional<VkMemoryPropertyFlags> fallbackFlags;
193194
auto flags = GetMemoryPropertyFlags(resourceType, fallbackFlags);
194195
auto memoryTypeIndex = GetMemoryTypeIndex(memReqs.memoryTypeBits, flags);
195196
if (!memoryTypeIndex && fallbackFlags)
196197
{
197-
flags = fallbackFlags.value();
198+
flags = *fallbackFlags;
198199
memoryTypeIndex = GetMemoryTypeIndex(memReqs.memoryTypeBits, flags);
199200
}
200201

@@ -209,7 +210,7 @@ VulkanMemoryManager::AllocationPtr VulkanMemoryManager::Allocate(ResourceType re
209210
memAllocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
210211
memAllocInfo.pNext = nullptr;
211212
memAllocInfo.allocationSize = blockSize;
212-
memAllocInfo.memoryTypeIndex = memoryTypeIndex.value();
213+
memAllocInfo.memoryTypeIndex = *memoryTypeIndex;
213214
IncrementTotalAllocationsCount();
214215
CHECK_VK_CALL(vkAllocateMemory(m_device, &memAllocInfo, nullptr, &memory));
215216
m_sizes[static_cast<size_t>(resourceType)] += blockSize;

0 commit comments

Comments
 (0)