Skip to content

unterumarmung/fixed_string

Folders and files

NameName
Last commit message
Last commit date
Jan 2, 2022
Nov 19, 2020
Jan 16, 2022
Jan 3, 2022
Aug 15, 2021
Nov 20, 2020
Jan 2, 2022
Nov 23, 2020
Nov 24, 2020
Jul 2, 2021
Jan 28, 2021

Repository files navigation

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
constexpr fixstr::fixed_string foo = "foo";
  • Concatenation
using namespace fixstr;
constexpr fixed_string first = "Hello, ";
constexpr fixed_string second = "World!";
constexpr auto result = first + second; // "Hello, World!"
  • Comparison
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
template <fixstr::fixed_string Foo>
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 on your project for external dependencies, then you can use the fixed-string package.

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