mirror of
https://github.com/boostorg/static_string.git
synced 2026-01-20 17:12:13 +00:00
Compare commits
10 Commits
develop
...
add_basic_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ec624ed0d4 | ||
|
|
f699d8db04 | ||
|
|
e3e77f3ec2 | ||
|
|
aa3f7eae02 | ||
|
|
739060f809 | ||
|
|
8de075835b | ||
|
|
95c8c1edec | ||
|
|
ade9f2e509 | ||
|
|
7e720a959b | ||
|
|
38bbebe9cd |
138
.github/workflows/example.yml
vendored
138
.github/workflows/example.yml
vendored
@@ -25,132 +25,14 @@ on:
|
||||
- meta/**
|
||||
- README.md
|
||||
|
||||
env:
|
||||
B2_TARGETS: libs/$SELF/example
|
||||
|
||||
jobs:
|
||||
linux:
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- { toolset: gcc-13, cxxstd: '20,23' }
|
||||
- { toolset: gcc-14, cxxstd: '20,23,26' }
|
||||
- { toolset: clang-17, cxxstd: '20,23' }
|
||||
- { toolset: clang-18, cxxstd: '20,23,26' }
|
||||
|
||||
steps:
|
||||
- name: Checkout Boost super-project
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: boostorg/boost
|
||||
ref: develop
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Checkout this library
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
path: libs/static_string
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Initialize Boost submodules
|
||||
run: |
|
||||
git submodule update --init tools/boostdep
|
||||
python tools/boostdep/depinst/depinst.py --git_args '--jobs 4' static_string
|
||||
|
||||
- name: Bootstrap b2
|
||||
run: ./bootstrap.sh
|
||||
|
||||
- name: Generate Boost headers
|
||||
run: ./b2 headers
|
||||
|
||||
- name: Build and run example tests
|
||||
run: |
|
||||
./b2 libs/static_string/example/static_cstring \
|
||||
toolset=${{ matrix.toolset }} \
|
||||
cxxstd=${{ matrix.cxxstd }} \
|
||||
variant=debug,release \
|
||||
-j$(nproc)
|
||||
|
||||
macos:
|
||||
runs-on: macos-14
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- { toolset: clang, cxxstd: '20,23' }
|
||||
|
||||
steps:
|
||||
- name: Checkout Boost super-project
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: boostorg/boost
|
||||
ref: develop
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Checkout this library
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
path: libs/static_string
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Initialize Boost submodules
|
||||
run: |
|
||||
git submodule update --init tools/boostdep
|
||||
python3 tools/boostdep/depinst/depinst.py --git_args '--jobs 4' static_string
|
||||
|
||||
- name: Bootstrap b2
|
||||
run: ./bootstrap.sh
|
||||
|
||||
- name: Generate Boost headers
|
||||
run: ./b2 headers
|
||||
|
||||
- name: Build and run example tests
|
||||
run: |
|
||||
./b2 libs/static_string/example/static_cstring \
|
||||
toolset=${{ matrix.toolset }} \
|
||||
cxxstd=${{ matrix.cxxstd }} \
|
||||
variant=debug,release \
|
||||
-j$(sysctl -n hw.ncpu)
|
||||
|
||||
windows:
|
||||
runs-on: windows-2022
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- { toolset: msvc-14.3, cxxstd: '20,latest' }
|
||||
|
||||
steps:
|
||||
- name: Checkout Boost super-project
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
repository: boostorg/boost
|
||||
ref: develop
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Checkout this library
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
path: libs/static_string
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Initialize Boost submodules
|
||||
run: |
|
||||
git submodule update --init tools/boostdep
|
||||
python tools/boostdep/depinst/depinst.py --git_args '--jobs 4' static_string
|
||||
|
||||
- name: Bootstrap b2
|
||||
run: .\bootstrap.bat
|
||||
shell: cmd
|
||||
|
||||
- name: Generate Boost headers
|
||||
run: .\b2 headers
|
||||
shell: cmd
|
||||
|
||||
- name: Build and run example tests
|
||||
run: |
|
||||
.\b2 libs/static_string/example/static_cstring ^
|
||||
toolset=${{ matrix.toolset }} ^
|
||||
cxxstd=${{ matrix.cxxstd }} ^
|
||||
variant=debug,release ^
|
||||
address-model=64
|
||||
shell: cmd
|
||||
call-boost-ci:
|
||||
name: Run Boost.CI
|
||||
uses: boostorg/boost-ci/.github/workflows/reusable.yml@master
|
||||
with:
|
||||
exclude_cxxstd: '98,03,0x,11,14,17'
|
||||
enable_pr_coverage: false
|
||||
enable_multiarch: false
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace static_strings {
|
||||
|
||||
namespace detail {
|
||||
|
||||
// Primary template: No remaining-capacity trick; uses traits::length() for length.
|
||||
// Primary template: No remaining-capacity trick; uses traits::length() for size.
|
||||
template<std::size_t N, typename CharT, typename Traits, bool UseRemaining>
|
||||
class static_cstring_base
|
||||
{
|
||||
@@ -46,12 +46,17 @@ public:
|
||||
data_[sz] = value_type{};
|
||||
}
|
||||
|
||||
constexpr void init_empty() noexcept
|
||||
{
|
||||
data_[0] = value_type{};
|
||||
}
|
||||
|
||||
// Defaulted comparisons for structural type support.
|
||||
constexpr bool operator==(const static_cstring_base&) const noexcept = default;
|
||||
constexpr auto operator<=>(const static_cstring_base&) const noexcept = default;
|
||||
};
|
||||
|
||||
// Specialization for N <= UCHAR_MAX: Uses remaining-capacity trick.
|
||||
// Specialization for N <= UCHAR_MAX: Use remaining-capacity trick.
|
||||
template<std::size_t N, typename CharT, typename Traits>
|
||||
class static_cstring_base<N, CharT, Traits, true>
|
||||
{
|
||||
@@ -73,6 +78,12 @@ public:
|
||||
data_[N] = static_cast<value_type>(N - sz);
|
||||
}
|
||||
|
||||
constexpr void init_empty() noexcept
|
||||
{
|
||||
data_[0] = value_type{};
|
||||
data_[N] = static_cast<value_type>(N);
|
||||
}
|
||||
|
||||
// Defaulted comparisons for structural type support.
|
||||
constexpr bool operator==(const static_cstring_base&) const noexcept = default;
|
||||
constexpr auto operator<=>(const static_cstring_base&) const noexcept = default;
|
||||
@@ -89,6 +100,7 @@ public:
|
||||
using base::data_;
|
||||
using base::get_size;
|
||||
using base::set_size;
|
||||
using base::init_empty;
|
||||
|
||||
// Member types
|
||||
using traits_type = Traits;
|
||||
@@ -108,7 +120,7 @@ public:
|
||||
// Constructors.
|
||||
constexpr basic_static_cstring() noexcept
|
||||
{
|
||||
set_size(0);
|
||||
init_empty();
|
||||
}
|
||||
|
||||
constexpr basic_static_cstring(const CharT* s)
|
||||
@@ -189,25 +201,21 @@ public:
|
||||
|
||||
constexpr reference front() noexcept
|
||||
{
|
||||
BOOST_STATIC_STRING_ASSERT(!empty());
|
||||
return data_[0];
|
||||
}
|
||||
|
||||
constexpr const_reference front() const noexcept
|
||||
{
|
||||
BOOST_STATIC_STRING_ASSERT(!empty());
|
||||
return data_[0];
|
||||
}
|
||||
|
||||
constexpr reference back() noexcept
|
||||
{
|
||||
BOOST_STATIC_STRING_ASSERT(!empty());
|
||||
return data_[size() - 1];
|
||||
}
|
||||
|
||||
constexpr const_reference back() const noexcept
|
||||
{
|
||||
BOOST_STATIC_STRING_ASSERT(!empty());
|
||||
return data_[size() - 1];
|
||||
}
|
||||
|
||||
@@ -260,7 +268,7 @@ public:
|
||||
// Modifiers.
|
||||
constexpr void clear() noexcept
|
||||
{
|
||||
set_size(0);
|
||||
init_empty();
|
||||
}
|
||||
|
||||
constexpr basic_static_cstring& assign(const CharT* s)
|
||||
|
||||
@@ -75,39 +75,41 @@ testCStringRemainingCapacityTrick()
|
||||
large.assign(100, 'x');
|
||||
BOOST_TEST(large.size() == 100);
|
||||
BOOST_TEST(large.capacity() == UCHAR_MAX);
|
||||
BOOST_TEST(static_cast<unsigned char>(large.data()[UCHAR_MAX]) == (UCHAR_MAX - large.size()));
|
||||
BOOST_TEST(static_cast<unsigned char>(large.data()[UCHAR_MAX]) == (large.capacity() - large.size()));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
struct CStringTypeTraits
|
||||
{
|
||||
static_assert(std::is_trivially_copyable<S>::value);
|
||||
static_assert(std::is_trivially_copy_constructible<S>::value);
|
||||
static_assert(std::is_trivially_move_constructible<S>::value);
|
||||
static_assert(std::is_trivially_copy_assignable<S>::value);
|
||||
static_assert(std::is_trivially_move_assignable<S>::value);
|
||||
static_assert(std::is_trivially_destructible<S>::value);
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
testCStringTypeTraits()
|
||||
{
|
||||
// static_cstring should be trivially copyable for use in POD structs.
|
||||
{
|
||||
using S = static_cstring<0>;
|
||||
CStringTypeTraits< S > check;
|
||||
static_cast<void>(check);
|
||||
static_assert(std::is_trivially_copyable<S>::value, "");
|
||||
static_assert(std::is_trivially_copy_constructible<S>::value, "");
|
||||
static_assert(std::is_trivially_move_constructible<S>::value, "");
|
||||
static_assert(std::is_trivially_copy_assignable<S>::value, "");
|
||||
static_assert(std::is_trivially_move_assignable<S>::value, "");
|
||||
static_assert(std::is_trivially_destructible<S>::value, "");
|
||||
}
|
||||
{
|
||||
using S = static_cstring<63>;
|
||||
CStringTypeTraits< S > check;
|
||||
static_cast<void>(check);
|
||||
static_assert(std::is_trivially_copyable<S>::value, "");
|
||||
static_assert(std::is_trivially_copy_constructible<S>::value, "");
|
||||
static_assert(std::is_trivially_move_constructible<S>::value, "");
|
||||
static_assert(std::is_trivially_copy_assignable<S>::value, "");
|
||||
static_assert(std::is_trivially_move_assignable<S>::value, "");
|
||||
static_assert(std::is_trivially_destructible<S>::value, "");
|
||||
}
|
||||
{
|
||||
using S = static_cstring<300>;
|
||||
CStringTypeTraits< S > check;
|
||||
static_cast<void>(check);
|
||||
static_assert(std::is_trivially_copyable<S>::value, "");
|
||||
static_assert(std::is_trivially_copy_constructible<S>::value, "");
|
||||
static_assert(std::is_trivially_move_constructible<S>::value, "");
|
||||
static_assert(std::is_trivially_copy_assignable<S>::value, "");
|
||||
static_assert(std::is_trivially_move_assignable<S>::value, "");
|
||||
static_assert(std::is_trivially_destructible<S>::value, "");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,8 +72,9 @@ struct cxper_char_traits
|
||||
// This implementation does not handle overlapping ranges where
|
||||
// dest > src. A correct implementation would need to detect this
|
||||
// case and copy backwards, but detecting overlap requires pointer
|
||||
// comparisons that many of the tested compiles (incorrectly) refuse
|
||||
// in constant expressions.
|
||||
// comparisons that are not allowed in constant expressions when
|
||||
// the pointers point to unrelated objects (e.g., a string literal
|
||||
// and the static_string's internal buffer).
|
||||
//
|
||||
// Since cxper_char_traits is only used for testing constexpr
|
||||
// functionality and the tests do not exercise overlapping moves
|
||||
|
||||
Reference in New Issue
Block a user