beman.cstring_view
beman.cstring_view: cstring_view, a null-terminated string view
beman.cstring_view is a header-only cstring_view library.
Implements: std::cstring_view proposed in cstring_view (P3655R2).
Usage
std::cstring_view exposes a string_view like type that is intended for being able to propagate prior knowledge that a string is null-terminated throughout the type system, while fulfilling the same role as string_view.
The following code snippet illustrates how we can use cstring_view to make a beginner-friendly main:
#include <beman/cstring_view/cstring_view.hpp>
#include <vector>
int main(int argc, const char** argv) {
std::vector<cstring_view> args(argv, argv+argc);
}
Full runnable examples can be found in examples/.
Dependencies
Build Environment
This project requires at least the following to build:
-
A C compiler that conforms to the C20 standard or greater
-
CMake 3.30 or later
-
(Test Only) GoogleTest
You can disable building tests by setting CMake option BEMAN_CSTRING_VIEW_BUILD_TESTS to OFF when configuring the project.
Supported Platforms
| Compiler | Version | C++ Standards | Standard Library |
|---|---|---|---|
GCC |
16-13 |
C26-C17 |
libstdc++ |
GCC |
12-11 |
C23-C17 |
libstdc++ |
Clang |
22-19 |
C26-C17 |
libstdc, libc |
Clang |
18 |
C26-C17 |
libc++ |
Clang |
18 |
C23-C17 |
libstdc++ |
Clang |
17 |
C26-C17 |
libc++ |
Clang |
17 |
C20, C17 |
libstdc++ |
AppleClang |
latest |
C26-C17 |
libc++ |
MSVC |
latest |
C++23 |
MSVC STL |
Development
See the Contributing Guidelines.
Integrate beman.cstring_view into your project
Build
You can build cstring_view using a CMake workflow preset:
cmake --workflow --preset gcc-release
To list available workflow presets, you can invoke:
cmake --list-presets=workflow
For details on building beman.cstring_view without using a CMake preset, refer to the Contributing Guidelines.
Installation
Vcpkg
The preferred way to install cstring_view is via vcpkg. To do so, after installing vcpkg itself, you need to add support for the Beman project’s vcpkg registry by configuring a vcpkg-configuration.json file (which cstring_view provides).
Then, simply run vcpkg install beman-cstring-view.
Manual
To install beman.cstring_view globally after building with the gcc-release preset, you can run:
sudo cmake --install build/gcc-release
Alternatively, to install to a prefix, for example /opt/beman, you can run:
sudo cmake --install build/gcc-release --prefix /opt/beman
This will generate the following directory structure:
/opt/beman
├── include
│ └── beman
│ └── cstring_view
│ ├── cstring_view.hpp
│ └── ...
└── lib
└── cmake
└── beman.cstring_view
├── beman.cstring_view-config-version.cmake
├── beman.cstring_view-config.cmake
└── beman.cstring_view-targets.cmake
CMake Configuration
If you installed beman.cstring_view to a prefix, you can specify that prefix to your CMake project using CMAKE_PREFIX_PATH; for example, -DCMAKE_PREFIX_PATH=/opt/beman.
You need to bring in the beman.cstring_view package to define the beman::cstring_view CMake target:
find_package(beman.cstring_view REQUIRED)
You will then need to add beman::cstring_view to the link libraries of any libraries or executables that include beman.cstring_view headers.
target_link_libraries(yourlib PUBLIC beman::cstring_view)