beast icon indicating copy to clipboard operation
beast copied to clipboard

Use core::string_view directly instead of alias

Open ssam18 opened this issue 5 months ago • 11 comments

This PR addresses issue #3046 by replacing all uses of the string_view alias with core::string_view throughout the codebase for improved clarity in both documentation and source code.

Changes

  • Replaced string_view with core::string_view in all header files (.hpp)
  • Replaced string_view with core::string_view in all inline implementation files (.ipp)
  • Updated documentation files (.qbk) to use core::string_view
  • Replaced basic_string_view with core::basic_string_view where applicable
  • Retained type aliases in string_type.hpp for backward compatibility

Benefits

  • Makes it explicit that Beast uses boost::core::string_view
  • Improves code clarity and documentation
  • Easier for users to understand the library's dependencies

Files Modified

  • 48 header and implementation files
  • 4 documentation files
  • Total: 52 files with 410 insertions and 347 deletions

Closes #3046

ssam18 avatar Nov 18 '25 01:11 ssam18

An automated preview of the documentation is available at https://3058.beast.prtest.cppalliance.org/libs/beast/doc/html/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2025-11-30 16:23:30 UTC

cppalliance-bot avatar Nov 18 '25 02:11 cppalliance-bot

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 93.19%. Comparing base (67106eb) to head (7188b56).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3058      +/-   ##
===========================================
- Coverage    93.22%   93.19%   -0.03%     
===========================================
  Files          176      176              
  Lines        13703    13703              
===========================================
- Hits         12774    12770       -4     
- Misses         929      933       +4     
Files with missing lines Coverage Δ
example/doc/http_examples.hpp 80.36% <100.00%> (ø)
...ude/boost/beast/_experimental/test/impl/stream.ipp 98.36% <ø> (ø)
include/boost/beast/_experimental/test/stream.hpp 75.00% <ø> (ø)
.../boost/beast/core/detail/impl/temporary_buffer.ipp 100.00% <ø> (ø)
include/boost/beast/core/detail/string.hpp 100.00% <100.00%> (ø)
...clude/boost/beast/core/detail/temporary_buffer.hpp 100.00% <ø> (ø)
include/boost/beast/core/impl/string.ipp 100.00% <ø> (ø)
include/boost/beast/core/string_type.hpp 100.00% <100.00%> (ø)
include/boost/beast/http/basic_parser.hpp 94.11% <ø> (ø)
include/boost/beast/http/chunk_encode.hpp 100.00% <ø> (ø)
... and 30 more

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 67106eb...7188b56. Read the comment docs.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Nov 18 '25 03:11 codecov[bot]

Thank you. Could you please check the example and test directories as well?

ashtum avatar Nov 18 '25 05:11 ashtum

This is great!

vinniefalco avatar Nov 18 '25 07:11 vinniefalco

Thank you @ashtum for the review! I've updated the PR to:

  1. Process example and test directories - added 58 more files with string_view replacements
  2. Remove replace_string_view.py from the committed files

ssam18 avatar Nov 18 '25 14:11 ssam18

Thank you for the detailed review! I've addressed all the feedback:

  1. Removed the type aliases from string_type.hpp as they're no longer needed since all code now uses core::string_view directly
  2. Removed the .gitignore entry for replace_string_view.py

ssam18 avatar Nov 18 '25 15:11 ssam18

Fixed all remaining comment alignment issues.

ssam18 avatar Nov 18 '25 16:11 ssam18

@ssam18 You can use the GitHub Action CI in your own fork to address the compile errors, since it won’t require approval to run each time.

ashtum avatar Nov 18 '25 17:11 ashtum

Why the core::string_view → boost::core::string_view change is necessary?

The issue:

C++ namespace lookup rules mean that when you write core::string_view in a file, the compiler searches for core starting from the current namespace and working outward. This works fine in files already inside namespace boost { ... } because the compiler finds boost::core. But in standalone example and test files that aren't wrapped in the boost namespace, the compiler can't find core at all.

FIX:

Files need to use the fully qualified name boost::core::string_view unless they're already inside the boost namespace. This is why:

Example files (like example/http/server/async/http_server_async.cpp) → Need boost::core::string_view (standalone programs) Test/doc files outside boost namespace → Need boost::core::string_view Header files inside namespace boost (like example/doc/http_examples.hpp) → Can use core::string_view (already in boost namespace) This is standard C++ namespace behavior—you need the full qualification when you're not already in the parent namespace. The changes ensure MSVC (and all other compilers) can properly resolve the type regardless of where it's used.

ssam18 avatar Nov 18 '25 23:11 ssam18

@ashtum Please let me know if this PR looks good?

ssam18 avatar Nov 30 '25 15:11 ssam18

@ashtum Please let me know if this PR looks good?

All files under test/doc and example should use core::string_view rather than boost::string_view. If needed, add namespace core = boost::core; in the correct location, following the style of nearby using declarations.

For example:

namespace beast = boost::beast;          // from <boost/beast.hpp>
namespace http = beast::http;            // from <boost/beast/http.hpp>
namespace websocket = beast::websocket;  // from <boost/beast/websocket.hpp>
namespace net = boost::asio;             // from <boost/asio.hpp>
namespace ssl = boost::asio::ssl;        // from <boost/asio/ssl.hpp>
namespace core = boost::core;            // from <boost/core/detail/string_view.hpp>
using tcp = boost::asio::ip::tcp;        // from <boost/asio/ip/tcp.hpp>

Please review each changed line manually and use your judgment to fix any formatting, clarity, or semantic issues. Please run the CI on your branch and address the build failures (you need to activate GHA action for your fork).

ashtum avatar Nov 30 '25 15:11 ashtum