Merged
Conversation
- Replace `boost::optional` with `std::optional` - Replace `boost::any` with `std::any` - Use `std::weak_from_this` to create a `weak_ptr` from a `shared_ptr` - Leverage initializers for if to simplify code
There was a problem hiding this comment.
Pull request overview
This PR upgrades the C++ standard requirement from C++11 to C++17 for the Pulsar C++ client library, bumping the version to 4.0.0-pre. The upgrade modernizes the codebase by replacing Boost types with their standard library equivalents and leveraging C++17 language features for cleaner, more maintainable code.
Key Changes:
- Replaced
boost::optionalwithstd::optionalandboost::anywithstd::anythroughout the codebase - Adopted
std::weak_from_this()for creating weak pointers fromshared_from_this() - Introduced if-initializers to reduce variable scope and improve code clarity in async callback patterns
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| version.txt | Bumped version from 3.8.0-pre to 4.0.0-pre |
| CMakeLists.txt | Set CMAKE_CXX_STANDARD to 17 (moved from INTEGRATE_VCPKG block to global scope) |
| README.md | Added documentation noting C++17 requirement starting from version 4.0.0 |
| pkg/mac/build-static-library.sh | Updated compiler flags from -std=c++11 to -std=c++17 |
| pkg/apk/build-apk.sh | Updated compiler flags from -std=c++11 to -std=c++17 |
| lib/SynchronizedHashMap.h | Replaced boost::optional with std::optional, updated comments and return patterns |
| lib/ProducerConfigurationImpl.h | Replaced boost::optional with std::optional for member variables |
| lib/ProducerConfiguration.cc | Replaced boost::make_optional with std::make_optional |
| lib/ProducerImpl.h | Replaced boost::optional with optional for method parameters and member variables |
| lib/ProducerImpl.cc | Updated to use std::optional, replaced nullptr with {} for optional initialization |
| lib/HandlerBase.h | Replaced boost::optional with optional in method signatures |
| lib/HandlerBase.cc | Adopted weak_from_this() and if-initializers, replaced nullptr with {} for optional |
| lib/ConsumerImpl.h | Replaced boost::optional with optional in method signatures and member variables |
| lib/ConsumerImpl.cc | Comprehensive migration to std::optional, adopted weak_from_this() and if-initializers |
| lib/ConsumerImplBase.cc | Adopted weak_from_this() and if-initializers with static_pointer_cast for proper typing |
| lib/MultiTopicsConsumerImpl.h | Updated constructor parameters to use optional with default values |
| lib/MultiTopicsConsumerImpl.cc | Adopted weak_from_this(), changed optional access from get() to value() |
| lib/Commands.h | Replaced boost::optional with optional in function signatures |
| lib/Commands.cc | Updated function parameters to use optional, added boost/throw_exception.hpp include |
| lib/ClientConnection.h | Replaced boost::any with std::any, removed C++14 weak_from_this workaround, replaced boost::optional with optional |
| lib/ClientConnection.cc | Replaced boost::any_cast with std::any_cast, updated optional value construction |
| lib/ProducerStatsImpl.cc | Adopted weak_from_this() for cleaner code |
| lib/ConsumerStatsImpl.cc | Adopted weak_from_this() for cleaner code |
| lib/UnAckedMessageTrackerEnabled.cc | Adopted weak_from_this() and if-initializers |
| lib/TableViewImpl.cc | Updated containsKey to use static_cast for optional checking, adopted weak_from_this() |
| lib/PeriodicTask.cc | Adopted weak_from_this() and if-initializers |
| lib/NegativeAcksTracker.cc | Adopted weak_from_this() for cleaner code |
| lib/RetryableOperationCache.h | Adopted weak_from_this() for cleaner code |
| lib/AckGroupingTrackerEnabled.cc | Adopted weak_from_this() and if-initializers |
| tests/SynchronizedHashMapTest.cc | Updated tests to use std::optional syntax, removed boost include |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
RobertIndie
approved these changes
Dec 3, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
boost::optionalwithstd::optionalboost::anywithstd::anystd::weak_from_thisto create aweak_ptrfrom ashared_ptrSet the next major version to 4.0.0 for this change. If there are still demands from community for C++11 based build, we can consider 3.x.y releases.