Skip to content

Conversation

@BewareMyPower
Copy link
Contributor

  • 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

Set 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.

- 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
@BewareMyPower BewareMyPower self-assigned this Dec 1, 2025
@BewareMyPower BewareMyPower added this to the 3.9.0 milestone Dec 1, 2025
@RobertIndie RobertIndie requested a review from Copilot December 1, 2025 14:58
Copilot finished reviewing on behalf of RobertIndie December 1, 2025 15:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::optional with std::optional and boost::any with std::any throughout the codebase
  • Adopted std::weak_from_this() for creating weak pointers from shared_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.

@BewareMyPower BewareMyPower marked this pull request as draft December 2, 2025 07:58
@BewareMyPower BewareMyPower marked this pull request as ready for review December 3, 2025 10:40
@BewareMyPower BewareMyPower merged commit c64e0e9 into apache:main Dec 3, 2025
23 of 26 checks passed
@BewareMyPower BewareMyPower deleted the bewaremypower/cpp-17 branch December 3, 2025 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants