Skip to content

bemanproject/cstring_view

Repository files navigation

beman.cstring_view: cstring_view, a null-terminated string view

Library Status Continuous Integration Tests Lint Check (pre-commit) Coverage Standard Target Compiler Explorer Example

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.

License

beman.cstring_view is licensed under the Apache License v2.0 with LLVM Exceptions.

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

Supported Platforms

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

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

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)

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

About

cstring_view following P3655

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors