Skip to content

Commit e9313dc

Browse files
committed
Add an experimental basic_static_cstring template in example/
This introduces an alternative to basic_static_string designed for use in POD types: Trivially copyable, having a sizeof == N + 1, with no embedded NULs. Placed in example/ to gather user feedback before committing to a public API. See issue #23.
1 parent 0c5e5b8 commit e9313dc

5 files changed

Lines changed: 1300 additions & 0 deletions

File tree

.github/workflows/example.yml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#
2+
# Copyright (c) 2025 Gennaro Prota (gennaro dot prota at gmail dot com)
3+
#
4+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
# file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
6+
#
7+
# Official repository: https://github.com/boostorg/static_string
8+
#
9+
10+
name: Example (basic_static_cstring)
11+
12+
on:
13+
pull_request:
14+
push:
15+
branches:
16+
- master
17+
- develop
18+
- bugfix/**
19+
- feature/**
20+
- fix/**
21+
- github/**
22+
- pr/**
23+
paths-ignore:
24+
- LICENSE
25+
- meta/**
26+
- README.md
27+
28+
jobs:
29+
linux:
30+
runs-on: ubuntu-24.04
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
include:
35+
- { toolset: gcc-13, cxxstd: '20,23' }
36+
- { toolset: gcc-14, cxxstd: '20,23,26' }
37+
- { toolset: clang-17, cxxstd: '20,23' }
38+
- { toolset: clang-18, cxxstd: '20,23,26' }
39+
40+
steps:
41+
- name: Checkout Boost super-project
42+
uses: actions/checkout@v4
43+
with:
44+
repository: boostorg/boost
45+
ref: develop
46+
fetch-depth: 0
47+
48+
- name: Checkout this library
49+
uses: actions/checkout@v4
50+
with:
51+
path: libs/static_string
52+
fetch-depth: 0
53+
54+
- name: Initialize Boost submodules
55+
run: |
56+
git submodule update --init tools/boostdep
57+
python tools/boostdep/depinst/depinst.py --git_args '--jobs 4' static_string
58+
59+
- name: Bootstrap b2
60+
run: ./bootstrap.sh
61+
62+
- name: Generate Boost headers
63+
run: ./b2 headers
64+
65+
- name: Build and run example tests
66+
run: |
67+
./b2 libs/static_string/example/static_cstring \
68+
toolset=${{ matrix.toolset }} \
69+
cxxstd=${{ matrix.cxxstd }} \
70+
variant=debug,release \
71+
-j$(nproc)
72+
73+
macos:
74+
runs-on: macos-14
75+
strategy:
76+
fail-fast: false
77+
matrix:
78+
include:
79+
- { toolset: clang, cxxstd: '20,23' }
80+
81+
steps:
82+
- name: Checkout Boost super-project
83+
uses: actions/checkout@v4
84+
with:
85+
repository: boostorg/boost
86+
ref: develop
87+
fetch-depth: 0
88+
89+
- name: Checkout this library
90+
uses: actions/checkout@v4
91+
with:
92+
path: libs/static_string
93+
fetch-depth: 0
94+
95+
- name: Initialize Boost submodules
96+
run: |
97+
git submodule update --init tools/boostdep
98+
python3 tools/boostdep/depinst/depinst.py --git_args '--jobs 4' static_string
99+
100+
- name: Bootstrap b2
101+
run: ./bootstrap.sh
102+
103+
- name: Generate Boost headers
104+
run: ./b2 headers
105+
106+
- name: Build and run example tests
107+
run: |
108+
./b2 libs/static_string/example/static_cstring \
109+
toolset=${{ matrix.toolset }} \
110+
cxxstd=${{ matrix.cxxstd }} \
111+
variant=debug,release \
112+
-j$(sysctl -n hw.ncpu)
113+
114+
windows:
115+
runs-on: windows-2022
116+
strategy:
117+
fail-fast: false
118+
matrix:
119+
include:
120+
- { toolset: msvc-14.3, cxxstd: '20,latest' }
121+
122+
steps:
123+
- name: Checkout Boost super-project
124+
uses: actions/checkout@v4
125+
with:
126+
repository: boostorg/boost
127+
ref: develop
128+
fetch-depth: 0
129+
130+
- name: Checkout this library
131+
uses: actions/checkout@v4
132+
with:
133+
path: libs/static_string
134+
fetch-depth: 0
135+
136+
- name: Initialize Boost submodules
137+
run: |
138+
git submodule update --init tools/boostdep
139+
python tools/boostdep/depinst/depinst.py --git_args '--jobs 4' static_string
140+
141+
- name: Bootstrap b2
142+
run: .\bootstrap.bat
143+
shell: cmd
144+
145+
- name: Generate Boost headers
146+
run: .\b2 headers
147+
shell: cmd
148+
149+
- name: Build and run example tests
150+
run: |
151+
.\b2 libs/static_string/example/static_cstring ^
152+
toolset=${{ matrix.toolset }} ^
153+
cxxstd=${{ matrix.cxxstd }} ^
154+
variant=debug,release ^
155+
address-model=64
156+
shell: cmd

example/static_cstring/Jamfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Copyright (c) 2025 Gennaro Prota (gennaro dot prota at gmail dot com)
3+
#
4+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
# file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
6+
#
7+
# Official repository: https://github.com/boostorg/static_string
8+
#
9+
10+
import testing ;
11+
12+
project
13+
: requirements
14+
<include>../../include
15+
<warnings>extra
16+
<cxxstd>20
17+
;
18+
19+
run static_cstring_test.cpp ;

example/static_cstring/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
This directory contains an experimental implementation of `basic_static_cstring`, which differs from `basic_static_string` in the following ways:
2+
3+
| | `basic_static_cstring` | `basic_static_string` |
4+
|---------------------|------------------------|-----------------------|
5+
| Layout | `sizeof == N + 1` | Has size member |
6+
| Embedded NULs | Not supported | Supported |
7+
| Trivially copyable | Yes | No |
8+
9+
Additionally, when `N <= UCHAR_MAX`, `basic_static_cstring` employs an optimization that avoids calling `std::strlen()` to compute the size.
10+
11+
This work stems from [boostorg/static_string#23](https://github.com/boostorg/static_string/issues/23).
12+
13+
If you believe `basic_static_cstring` should become part of the public API, please share your feedback on the Boost mailing list.

0 commit comments

Comments
 (0)