Skip to content

david-grs/inplace_string

Repository files navigation

Build Status Build status Coverage Status

inplace_string<N, CharT, Traits>

An alternative to std::string with inplace storage. STL compliant, can be used as a full replacement of C++17's std::string.

Example

{
  using Name = inplace_string<15>; // 16 bytes on stack, size included
  Name name = "foo"; 

  auto it = name.find("r");
  assert(it == Name::npos);

  name += "bar";
  
  std::string str(name); // implicit std::string_view construction

  ....
}

{
  inplace_string<5> too_small;
  too_small = "foobar"; // error: static_assert failed "basic_inplace_string: size exceeds maximum capacity"
}

Compatibility

inplace_string<N, CharT, Traits> implements C++17's std::string interface, plus:

  • max_size() and capacity() are constexpr
  • inplace_string can be constructed from const CharT(&)[M]), allowing a compile-time error if the input exceeds the maximum capacity

Supports Clang >= 3.4, GCC >= 5, VS >= 2017

About

C++17 inplace_string implementation

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published