From 11df58bd4e1fecbea09060498560fb8d7591b921 Mon Sep 17 00:00:00 2001 From: Alexander Sopov Date: Tue, 12 Aug 2025 14:55:45 +0200 Subject: [PATCH] Use std::optional if available. Currently, SDK requires C++11 minimum. So, boost::optional type is used for optional values. For C++17 and above more convenient is to use std::optional instead. The task NLAM-23 is about making this type configurable. This commit makes the boost::optional default even for C++17 builds. The std::optional usage shall be switched on explicitly using OLP_SDK_USE_STD_OPTIONAL=ON flag. Relates-To: NLAM-23 Signed-off-by: sopov --- CMakeLists.txt | 2 +- docs/get-started.md | 4 ++-- olp-cpp-sdk-core/CMakeLists.txt | 4 ++-- olp-cpp-sdk-core/include/olp/core/porting/optional.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b47bbb625..1ece31a6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ endif() option(OLP_SDK_ENABLE_TESTING "Flag to enable/disable building unit and integration tests" ON) option(OLP_SDK_BUILD_DOC "Build SDK documentation" OFF) option(OLP_SDK_NO_EXCEPTION "Disable exception handling" OFF) -option(OLP_SDK_FORCE_BOOST_OPTIONAL "Use boost::optional instead of std::optional with C++17 and above" OFF) +option(OLP_SDK_USE_STD_OPTIONAL "Use std::optional instead of boost::optional with C++17 and above" OFF) option(OLP_SDK_BOOST_THROW_EXCEPTION_EXTERNAL "The boost::throw_exception() is defined externally" OFF) option(OLP_SDK_BUILD_EXTERNAL_DEPS "Download and build external dependencies" ON) option(OLP_SDK_BUILD_EXAMPLES "Enable examples targets" OFF) diff --git a/docs/get-started.md b/docs/get-started.md index fba7df784..3a62d72d7 100644 --- a/docs/get-started.md +++ b/docs/get-started.md @@ -130,7 +130,7 @@ cmake --build . --target docs | `OLP_SDK_ENABLE_TESTING` | Defaults to `ON`. If enabled, unit tests are built for each library. | | `OLP_SDK_BUILD_EXTERNAL_DEPS` | Defaults to `ON`. If enabled, CMake downloads and compiles dependencies. | | `OLP_SDK_NO_EXCEPTION` | Defaults to `OFF`. If enabled, all libraries are built without exceptions. | -| `OLP_SDK_FORCE_BOOST_OPTIONAL` | Defaults to `OFF`. If enabled, all libraries are built with boost::optional type even when std::optional is available. | +| `OLP_SDK_USE_STD_OPTIONAL` | Defaults to `OFF`. If enabled, all libraries are built with std::optional type instead of boost::optional for C++17 and above. | | `OLP_SDK_BOOST_THROW_EXCEPTION_EXTERNAL` | Defaults to `OFF`. When `OLP_SDK_NO_EXCEPTION` is `ON`, `boost` requires `boost::throw_exception()` to be defined. If enabled, the external definition of `boost::throw_exception()` is used. Otherwise, the library uses own definition. | | `OLP_SDK_MSVC_PARALLEL_BUILD_ENABLE` (Windows Only) | Defaults to `ON`. If enabled, the `/MP` compilation flag is added to build the Data SDK using multiple cores. | | `OLP_SDK_DISABLE_DEBUG_LOGGING`| Defaults to `OFF`. If enabled, the debug and trace level log messages are not printed. | @@ -176,4 +176,4 @@ HERE Data SDK for C++ contains several example programs that demonstrate some of - [Read example](dataservice-read-catalog-example.md) – demonstrates how to get catalog and partition metadata, as well as partition data. - [Read example for a stream layer](dataservice-read-from-stream-layer-example.md) – demonstrates how to get data from a stream layer. - [Cache example](dataservice-cache-example.md) – demonstrates how to get partition data and work with a mutable and protected cache. -- [Write example](dataservice-write-example.md) – demonstrates how to publish data to the HERE platform. \ No newline at end of file +- [Write example](dataservice-write-example.md) – demonstrates how to publish data to the HERE platform. diff --git a/olp-cpp-sdk-core/CMakeLists.txt b/olp-cpp-sdk-core/CMakeLists.txt index 908d970c8..aac162670 100644 --- a/olp-cpp-sdk-core/CMakeLists.txt +++ b/olp-cpp-sdk-core/CMakeLists.txt @@ -440,9 +440,9 @@ if (OLP_SDK_NO_EXCEPTION AND NOT OLP_SDK_BOOST_THROW_EXCEPTION_EXTERNAL) PRIVATE OLP_SDK_BOOST_THROW_EXCEPTION=1) endif() -if (OLP_SDK_FORCE_BOOST_OPTIONAL) +if (OLP_SDK_USE_STD_OPTIONAL) target_compile_definitions(${PROJECT_NAME} - PUBLIC OLP_CPP_SDK_USE_BOOST_OPTIONAL) + PUBLIC OLP_CPP_SDK_USE_STD_OPTIONAL) endif() target_include_directories(${PROJECT_NAME} PUBLIC diff --git a/olp-cpp-sdk-core/include/olp/core/porting/optional.h b/olp-cpp-sdk-core/include/olp/core/porting/optional.h index 7afdc4c80..3cfa5049d 100644 --- a/olp-cpp-sdk-core/include/olp/core/porting/optional.h +++ b/olp-cpp-sdk-core/include/olp/core/porting/optional.h @@ -19,7 +19,7 @@ #pragma once -#if (__cplusplus >= 201703L) && !defined(OLP_CPP_SDK_USE_BOOST_OPTIONAL) +#if (__cplusplus >= 201703L) && defined(OLP_CPP_SDK_USE_STD_OPTIONAL) #include namespace olp {