beman.cstring_view is a header-only cstring_view library.
Implements: std::cstring_view proposed in cstring_view (P3655R2).
Status: Under development and not yet ready for production use.
beman.cstring_view is licensed under the Apache License v2.0 with LLVM Exceptions.
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/.
This project requires at least the following to build:
- A C++ compiler that conforms to the C++20 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.
| Compiler | Version | C++ Standards | Standard Library |
|---|---|---|---|
| GCC | 15-14 | C++26-C++20 | libstdc++ |
| Clang | 22-19 | C++26-C++20 | libstdc++, libc++ |
| Clang | 18-17 | C++26-C++20 | libc++ |
| Clang | 18-17 | C++20 | libstdc++ |
| AppleClang | latest | C++26-C++20 | libc++ |
| MSVC | latest | C++23 | MSVC STL |
See the Contributing Guidelines.
You can build cstring_view using a CMake workflow preset:
cmake --workflow --preset gcc-releaseTo list available workflow presets, you can invoke:
cmake --list-presets=workflowFor details on building beman.cstring_view without using a CMake preset, refer to the Contributing Guidelines.
To install beman.cstring_view globally after building with the gcc-release preset, you can
run:
sudo cmake --install build/gcc-releaseAlternatively, to install to a prefix, for example /opt/beman, you can run:
sudo cmake --install build/gcc-release --prefix /opt/bemanThis 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.cmakeIf 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)To use beman.cstring_view in your C++ project,
include an appropriate beman.cstring_view header from your source code.
#include <beman/cstring_view/cstring_view.hpp>Note
beman.cstring_view headers are to be included with the beman/cstring_view/ prefix.
Altering include search paths to spell the include target another way (e.g.
#include <cstring_view.hpp>) is unsupported.