https://github.com/unterumarmung/fixed_string
C++17 string with fixed size
https://github.com/unterumarmung/fixed_string
constexpr cplusplus cpp-library cpp-templates cpp17 cpp17-library cpp20 header-only single-file
Last synced: 7 months ago
JSON representation
C++17 string with fixed size
- Host: GitHub
- URL: https://github.com/unterumarmung/fixed_string
- Owner: unterumarmung
- License: mit
- Created: 2020-11-19T10:44:14.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-02-05T09:17:54.000Z (almost 4 years ago)
- Last Synced: 2023-08-08T19:56:45.175Z (about 2 years ago)
- Topics: constexpr, cplusplus, cpp-library, cpp-templates, cpp17, cpp17-library, cpp20, header-only, single-file
- Language: C++
- Homepage: https://unterumarmung.github.io/fixed_string/
- Size: 1.05 MB
- Stars: 91
- Watchers: 3
- Forks: 11
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fixed_string
C++ library that provides a `basic_fixed_string` template that combines `std::array` fixed-size semantic and `std::string` semantic together
## Features
* C++17 or higher
* Header-only
* Dependency-free
* No dynamic allocations
* Fully constexpr
* Can be used as class non-type template parameter __(since C++20)__
## Examples
* Construction
```cpp
constexpr fixstr::fixed_string foo = "foo";
```
* Concatenation
```cpp
using namespace fixstr;
constexpr fixed_string first = "Hello, ";
constexpr fixed_string second = "World!";
constexpr auto result = first + second; // "Hello, World!"
```
* Comparison
```cpp
using namespace fixstr;
constexpr fixed_string first = "Hello, ";
constexpr fixed_string second = "World!";
static_assert(first == second); // false
static_assert(first != second); // true
static_assert(first < second); // true
static_assert(first <= second); // true
static_assert(first > second); // false
static_assert(first >= second); // false
static_assert(first <=> second != 0); // true
```
* Non-type template parameter
```cpp
template
void bar()
{
static_assert(Foo == "foo"sv);
}
void foo()
{
bar<"foo">();
}
```
## Integration
Since it's a header only library, you need just copy `fixed_string.hpp` to your project.
If you are using [vcpkg](https://github.com/Microsoft/vcpkg/) on your project for external dependencies, then you can use the [**fixed-string** package](https://github.com/microsoft/vcpkg/tree/master/ports/fixed-string).
If you are using Conan on your project for external dependencies, then you can use the Conan recipe located in the root of the repository.
## Compiler compatibility
* GCC >= 7.3
* Clang >= 5
* ICC >= 19.0.1
* MSVC >= 14.28 / Visual Studio 2019 (I don't have access to older VS versions right now, so it can work on older versions too)
**Using `basic_fixed_string` as class non-type template parameter full available in GCC >= 10 and VS 2019 16.9 or newer**