Skip to content

Commit

Permalink
add test and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Viatorus committed Mar 9, 2024
1 parent 41f3006 commit 4569a60
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 4 additions & 1 deletion include/emio/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class span_buffer : public buffer {
constexpr span_buffer(span_buffer&&) noexcept = delete;
constexpr span_buffer& operator=(const span_buffer&) = delete;
constexpr span_buffer& operator=(span_buffer&&) noexcept = delete;
constexpr ~span_buffer() override = default;
constexpr ~span_buffer() override;

/**
* Obtains a view over the underlying string object.
Expand Down Expand Up @@ -254,6 +254,9 @@ class span_buffer : public buffer {
std::span<char> span_;
};

// Out-of-line definition because of a GCC bug (93413). Fixed in GCC 13.
inline constexpr span_buffer::~span_buffer() = default;

/**
* This class fulfills the buffer API by providing a fixed-size storage.
* @tparam StorageSize The size of the storage.
Expand Down
30 changes: 29 additions & 1 deletion test/compile_test/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,38 @@
consteval auto created_with_span_buffer() {
std::array<char, 5> storage{};
emio::span_buffer buf{storage};
emio::result<std::span<char>> area = buf.get_write_area_of(4);
return storage;
}

consteval auto created_with_static_buffer() {
std::array<char, 5> storage{};
emio::static_buffer<5> buf{};
std::span<char> area = buf.get_write_area_of(5).value();
std::fill(area.begin(), area.end(), 'a');
std::copy(buf.view().begin(), buf.view().end(), storage.begin());
return storage;
}

consteval auto created_with_memory_buffer() {
std::array<char, 5> storage{};
emio::memory_buffer<0> buf{};
std::span<char> area = buf.get_write_area_of(5).value();
std::fill(area.begin(), area.end(), 'a');
std::copy(buf.view().begin(), buf.view().end(), storage.begin());
return storage;
}

consteval auto created_with_iterator_buffer() {
std::array<char, 5> storage{};
emio::iterator_buffer buf{storage.data()};
std::span<char> area = buf.get_write_area_of(5).value();
std::fill(area.begin(), area.end(), 'a');
return storage;
}

int main() {
created_with_span_buffer();
created_with_static_buffer();
created_with_memory_buffer();
created_with_iterator_buffer();
}

0 comments on commit 4569a60

Please sign in to comment.