Skip to content

Commit

Permalink
update freestanding impl
Browse files Browse the repository at this point in the history
  • Loading branch information
MacroModel committed Nov 28, 2024
1 parent d440eb0 commit adf1ecd
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 73 deletions.
26 changes: 13 additions & 13 deletions include/fast_io_freestanding_impl/generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,38 @@ class generator_promise
#ifdef __cpp_exceptions
::std::exception_ptr ex_ptr;
#endif
generator<T> get_return_object() noexcept;
inline generator<T> get_return_object() noexcept;

constexpr ::std::suspend_always initial_suspend() const noexcept
inline constexpr ::std::suspend_always initial_suspend() const noexcept
{
return {};
}
constexpr ::std::suspend_always final_suspend() const noexcept
inline constexpr ::std::suspend_always final_suspend() const noexcept
{
return {};
}
// template<typename U>
// requires ::std::same_as<::std::remove_reference_t<U>,::std::remove_reference_t<T>>
constexpr ::std::suspend_always yield_value(T value) noexcept
inline constexpr ::std::suspend_always yield_value(T value) noexcept
{
ptr = value;
// ptr = __builtin_addressof(value);
return {};
}
constexpr void unhandled_exception() noexcept
inline constexpr void unhandled_exception() noexcept
{
#ifdef __cpp_exceptions
ex_ptr = ::std::current_exception();
#else
::std::terminate();
#endif
}
constexpr void return_void() noexcept
inline constexpr void return_void() noexcept
{}
template <typename U>
::std::suspend_never await_transform(U &&value) = delete;
inline ::std::suspend_never await_transform(U &&value) = delete;

void rethrow_if_exception()
inline void rethrow_if_exception()
{
#ifdef __cpp_exceptions
if (ex_ptr)
Expand Down Expand Up @@ -143,12 +143,12 @@ class [[nodiscard]] generator
public:
using promise_type = details::generator_promise<T>;
::std::coroutine_handle<promise_type> handle;
constexpr generator(::std::coroutine_handle<promise_type> v)
inline constexpr generator(::std::coroutine_handle<promise_type> v)
: handle(v)
{}
constexpr generator(generator const &) noexcept = delete;
constexpr generator &operator=(generator const &) noexcept = delete;
constexpr ~generator()
inline constexpr generator(generator const &) noexcept = delete;
inline constexpr generator &operator=(generator const &) noexcept = delete;
inline constexpr ~generator()
{
handle.destroy();
}
Expand Down Expand Up @@ -214,4 +214,4 @@ inline generator<T> generator_promise<T>::get_return_object() noexcept
return {coroutine_handle::from_promise(*this)};
}
} // namespace details
} // namespace fast_io
} // namespace fast_io
10 changes: 5 additions & 5 deletions include/fast_io_freestanding_impl/io_buffer/io_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ class basic_io_buffer
: handle(::std::forward<Args>(args)...)
{
}
basic_io_buffer &operator=(basic_io_buffer const &) = delete;
basic_io_buffer(basic_io_buffer const &) = delete;
constexpr basic_io_buffer(basic_io_buffer &&__restrict other) noexcept
inline basic_io_buffer &operator=(basic_io_buffer const &) = delete;
inline basic_io_buffer(basic_io_buffer const &) = delete;
inline constexpr basic_io_buffer(basic_io_buffer &&__restrict other) noexcept
: input_buffer(::std::move(other.input_buffer)), output_buffer(::std::move(other.output_buffer)),
handle(::std::move(other.handle))
{
Expand Down Expand Up @@ -105,7 +105,7 @@ class basic_io_buffer
handle = handle_type();
}
}
constexpr basic_io_buffer &operator=(basic_io_buffer &&__restrict other) noexcept
inline constexpr basic_io_buffer &operator=(basic_io_buffer &&__restrict other) noexcept
{
::fast_io::details::destroy_basic_io_buffer(*this);
input_buffer = ::std::move(other.input_buffer);
Expand All @@ -116,7 +116,7 @@ class basic_io_buffer
return *this;
}

constexpr ~basic_io_buffer()
inline constexpr ~basic_io_buffer()
{
::fast_io::details::destroy_basic_io_buffer(*this);
}
Expand Down
2 changes: 1 addition & 1 deletion include/fast_io_freestanding_impl/io_buffer/mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace details
{

template <typename char_type>
constexpr ::std::size_t compute_default_buffer_size() noexcept
inline constexpr ::std::size_t compute_default_buffer_size() noexcept
{
if constexpr (::std::same_as<char_type, void>)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class basic_io_deco_filter
: handle(::std::forward<Args>(args)...), decorators(::fast_io::freestanding::forward<decotype>(d))
{
}
basic_io_deco_filter &operator=(basic_io_deco_filter const &) = delete;
basic_io_deco_filter(basic_io_deco_filter const &) = delete;
constexpr basic_io_deco_filter(basic_io_deco_filter &&__restrict other) noexcept
inline basic_io_deco_filter &operator=(basic_io_deco_filter const &) = delete;
inline basic_io_deco_filter(basic_io_deco_filter const &) = delete;
inline constexpr basic_io_deco_filter(basic_io_deco_filter &&__restrict other) noexcept
: input_buffer(::std::move(other.input_buffer)), handle(::std::move(other.handle)),
decorators(::std::move(other.decorators))
{
Expand Down Expand Up @@ -86,7 +86,7 @@ class basic_io_deco_filter
handle = handle_type();
}
}
constexpr basic_io_deco_filter &operator=(basic_io_deco_filter &&__restrict other) noexcept
inline constexpr basic_io_deco_filter &operator=(basic_io_deco_filter &&__restrict other) noexcept
{
::fast_io::details::destroy_basic_io_filter(*this);
input_buffer = ::std::move(other.input_buffer);
Expand All @@ -96,7 +96,7 @@ class basic_io_deco_filter
return *this;
}

constexpr ~basic_io_deco_filter()
inline constexpr ~basic_io_deco_filter()
{
::fast_io::details::destroy_basic_io_filter(*this);
}
Expand Down
20 changes: 10 additions & 10 deletions include/fast_io_freestanding_impl/scanners/line_scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ struct basic_line_scanner_buffer
char_type *begin_ptr{};
char_type *curr_ptr{};
char_type *end_ptr{};
constexpr buffer_type() noexcept
inline constexpr buffer_type() noexcept
: begin_ptr(nullptr), curr_ptr(nullptr), end_ptr(nullptr)
{}
buffer_type(buffer_type const &) = delete;
buffer_type &operator=(buffer_type const &) = delete;
constexpr buffer_type(buffer_type &&__restrict other) noexcept
inline buffer_type(buffer_type const &) = delete;
inline buffer_type &operator=(buffer_type const &) = delete;
inline constexpr buffer_type(buffer_type &&__restrict other) noexcept
: begin_ptr(other.begin_ptr), curr_ptr(other.curr_ptr), end_ptr(other.end_ptr)
{
other.end_ptr = other.curr_ptr = other.begin_ptr = nullptr;
}
constexpr buffer_type &operator=(buffer_type &&__restrict other) noexcept
inline constexpr buffer_type &operator=(buffer_type &&__restrict other) noexcept
{
::fast_io::details::deallocate_iobuf_space<false, char_type>(
this->begin_ptr, static_cast<::std::size_t>(this->end_ptr - this->begin_ptr));
Expand All @@ -30,7 +30,7 @@ struct basic_line_scanner_buffer
this->end_ptr = other.end_ptr;
other.end_ptr = other.curr_ptr = other.begin_ptr = nullptr;
}
constexpr ~buffer_type()
inline constexpr ~buffer_type()
{
::fast_io::details::deallocate_iobuf_space<false, char_type>(
this->begin_ptr, static_cast<::std::size_t>(this->end_ptr - this->begin_ptr));
Expand All @@ -40,11 +40,11 @@ struct basic_line_scanner_buffer
char_type const *view_begin_ptr{};
char_type const *view_end_ptr{};
bool inbuffer{};
constexpr char_type const *begin() const noexcept
inline constexpr char_type const *begin() const noexcept
{
return view_begin_ptr;
}
constexpr char_type const *end() const noexcept
inline constexpr char_type const *end() const noexcept
{
return view_end_ptr;
}
Expand All @@ -55,11 +55,11 @@ struct basic_line_scanner_contiguous_view
{
char_type const *view_begin_ptr{};
char_type const *view_end_ptr{};
constexpr char_type const *begin() const noexcept
inline constexpr char_type const *begin() const noexcept
{
return view_begin_ptr;
}
constexpr char_type const *end() const noexcept
inline constexpr char_type const *end() const noexcept
{
return view_end_ptr;
}
Expand Down
62 changes: 31 additions & 31 deletions include/fast_io_freestanding_impl/transcoders/transcoder_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ namespace fast_io

struct transcoder_file_base
{
virtual constexpr bool transcode_always_none() const = 0;
virtual constexpr ::std::size_t transcode_bytes_min_tosize() const = 0;
virtual constexpr ::std::size_t transcode_bytes_size(::std::byte const *, ::std::byte const *, ::std::size_t) const = 0;
virtual constexpr transcode_bytes_result transcode_bytes(::std::byte const *, ::std::byte const *, ::std::byte *, ::std::byte *) = 0;
virtual constexpr ::std::size_t transcode_bytes_do_final_tosize() const = 0;
virtual constexpr ::std::byte *transcode_bytes_do_final(::std::byte *, ::std::byte *) = 0;
virtual void destroy() noexcept = 0;
constexpr ~transcoder_file_base() = default;
inline virtual constexpr bool transcode_always_none() const = 0;
inline virtual constexpr ::std::size_t transcode_bytes_min_tosize() const = 0;
inline virtual constexpr ::std::size_t transcode_bytes_size(::std::byte const *, ::std::byte const *, ::std::size_t) const = 0;
inline virtual constexpr transcode_bytes_result transcode_bytes(::std::byte const *, ::std::byte const *, ::std::byte *, ::std::byte *) = 0;
inline virtual constexpr ::std::size_t transcode_bytes_do_final_tosize() const = 0;
inline virtual constexpr ::std::byte *transcode_bytes_do_final(::std::byte *, ::std::byte *) = 0;
inline virtual void destroy() noexcept = 0;
inline constexpr ~transcoder_file_base() = default;
};

template <typename allocator, typename T>
requires(::fast_io::transcoder<T> || ::fast_io::byte_transcoder<T>)
struct transcoder_file_derived final : transcoder_file_base
{
T object;
explicit constexpr basic_transcoder_file(::fast_io::io_cookie_type_t<T>, Args &&args...)
inline explicit constexpr basic_transcoder_file(::fast_io::io_cookie_type_t<T>, Args &&args...)
: object(::std::forward<Args>(args)...)
{
}
constexpr bool transcode_always_none() const override
inline constexpr bool transcode_always_none() const override
{
if constexpr (requires() {
object.transcode_always_none();
Expand All @@ -37,7 +37,7 @@ struct transcoder_file_derived final : transcoder_file_base
return false;
}
}
constexpr ::std::size_t transcode_bytes_min_tosize() const override
inline constexpr ::std::size_t transcode_bytes_min_tosize() const override
{
concept has_transcode_bytes_min_tosize = requires() {
{ object.transcode_bytes_min_tosize() } -> ::std::same_as<::std::size_t>;
Expand All @@ -51,7 +51,7 @@ struct transcoder_file_derived final : transcoder_file_base
return object.transcode_min_tosize() * sizeof(typename T::to_value_type);
}
}
constexpr ::std::size_t transcode_bytes_size(::std::byte const *fromfirst, ::std::byte const *fromlast, ::std::size_t mxsz) const override
inline constexpr ::std::size_t transcode_bytes_size(::std::byte const *fromfirst, ::std::byte const *fromlast, ::std::size_t mxsz) const override
{
concept has_transcode_bytes_size = requires() {
{ object.transcode_bytes_size(fromfirst, fromlast, mxsz) } -> ::std::same_as<::std::size_t>;
Expand All @@ -75,7 +75,7 @@ struct transcoder_file_derived final : transcoder_file_base
sizeof(from_value_type);
}
}
constexpr transcode_bytes_result transcode_bytes(::std::byte const *fromfirst, ::std::byte const *fromlast, ::std::byte *tofirst, ::std::byte *tolast) override
inline constexpr transcode_bytes_result transcode_bytes(::std::byte const *fromfirst, ::std::byte const *fromlast, ::std::byte *tofirst, ::std::byte *tolast) override
{
concept has_transcode_bytes = requires() {
{ object.transcode_bytes(fromfirst, fromlast, tofirst, tolast) } -> ::std::same_as<transcode_bytes_result>;
Expand Down Expand Up @@ -105,7 +105,7 @@ struct transcoder_file_derived final : transcoder_file_base
return {reinterpret_cast<::std::byte const *>(fromit), reinterpret_cast<::std::byte *>(toit)};
}
}
constexpr ::std::size_t transcode_bytes_do_final_tosize() override
inline constexpr ::std::size_t transcode_bytes_do_final_tosize() override
{
if constexpr (requires() {
{ object.transcode_bytes_do_final_tosize() } -> ::std::same_as<::std::size_t>;
Expand All @@ -124,7 +124,7 @@ struct transcoder_file_derived final : transcoder_file_base
return 0;
}
}
constexpr ::std::byte *transcode_bytes_do_final(::std::byte *tofirst, ::std::byte *tolast) override
inline constexpr ::std::byte *transcode_bytes_do_final(::std::byte *tofirst, ::std::byte *tolast) override
{
if constexpr (requires() {
{ object.transcode_bytes_do_final(tofirst, tolast) } -> ::std::same_as<::std::byte *>;
Expand Down Expand Up @@ -153,7 +153,7 @@ struct transcoder_file_derived final : transcoder_file_base
return fromfirst;
}
}
constexpr void destroy() noexcept override
inline constexpr void destroy() noexcept override
{
::std::destroy(this);
::fast_io::typed_allocator_adapter<allocator, ::fast_io::transcoder_file_derived<allocator, T>>::deallocate(this, 1);
Expand All @@ -165,38 +165,38 @@ class transcoder_io_observer
public:
using native_handle_type = transcoder_file_base *;
native_handle_type transhandle{};
constexpr native_handle_type release() noexcept
inline constexpr native_handle_type release() noexcept
{
auto temptranshandle{transhandle};
this->transhandle = nullptr;
return temptranshandle;
}
constexpr native_handle_type native_handle() const noexcept
inline constexpr native_handle_type native_handle() const noexcept
{
return this->transhandle;
}
constexpr bool transcode_always_none() const
inline constexpr bool transcode_always_none() const
{
return transhandle->transcode_always_none();
}
constexpr ::std::size_t transcode_bytes_minsize() const
inline constexpr ::std::size_t transcode_bytes_minsize() const
{
return transhandle->transcode_bytes_minsize();
}
constexpr ::std::size_t transcode_bytes_size(::std::byte const *fromfirst, ::std::byte const *fromlast, ::std::size_t mxsz) const
inline constexpr ::std::size_t transcode_bytes_size(::std::byte const *fromfirst, ::std::byte const *fromlast, ::std::size_t mxsz) const
{
return transhandle->transcode_bytes_size(fromfirst, fromlast, mxsz);
}
constexpr transcode_bytes_result transcode_bytes(::std::byte const *fromfirst, ::std::byte const *fromlast, ::std::byte *tofirst, ::std::byte *tolast)
inline constexpr transcode_bytes_result transcode_bytes(::std::byte const *fromfirst, ::std::byte const *fromlast, ::std::byte *tofirst, ::std::byte *tolast)
{
return transhandle->transcode_bytes(fromfirst, fromlast, tofirst, tolast);
}
constexpr ::std::size_t transcode_bytes_do_final_tosize() const
inline constexpr ::std::size_t transcode_bytes_do_final_tosize() const
{
return transhandle->transcode_bytes_do_final_tosize();
}

constexpr ::std::byte *transcode_bytes_do_final(::std::byte *tofirst, ::std::byte *tolast)
inline constexpr ::std::byte *transcode_bytes_do_final(::std::byte *tofirst, ::std::byte *tolast)
{
return transhandle->transcode_bytes_do_final(tofirst, tolast);
}
Expand All @@ -211,19 +211,19 @@ class basic_transcoder_file : public transcoder_io_observer
using transcoder_io_observer::transhandle;
template <typename T, typename... Args>
requires ::std::constructible_from<T, Args...>
explicit constexpr basic_transcoder_file(::fast_io::io_cookie_type_t<T>, Args &&args...)
inline explicit constexpr basic_transcoder_file(::fast_io::io_cookie_type_t<T>, Args &&args...)
: transcoder_io_observer{::std::construct_at(typed_allocator_adapter<allocator, ::fast_io::transcoder_file_derived<allocator, T>>::allocate(1), ::fast_io::io_cookie_type<T>, ::std::forward<Args>(args)...)}
{
}
constexpr basic_transcoder_file(basic_transcoder_file const &) = delete;
constexpr basic_transcoder_file &operator=(basic_transcoder_file const &) = delete;
inline constexpr basic_transcoder_file(basic_transcoder_file const &) = delete;
inline constexpr basic_transcoder_file &operator=(basic_transcoder_file const &) = delete;

constexpr basic_transcoder_file(basic_transcoder_file &&other) noexcept
inline constexpr basic_transcoder_file(basic_transcoder_file &&other) noexcept
: transhandle{other.handle}
{
other.transhandle = nullptr;
}
constexpr basic_transcoder_file &operator=(basic_transcoder_file &&other) noexcept
inline constexpr basic_transcoder_file &operator=(basic_transcoder_file &&other) noexcept
{
if (__builtin_addressof(other) == this)
{
Expand All @@ -234,12 +234,12 @@ class basic_transcoder_file : public transcoder_io_observer
other.transhandle = nullptr;
return *this;
}
constexpr void close() noexcept
inline constexpr void close() noexcept
{
this->transhandle->destroy();
this->transhandle = nullptr;
}
constexpr ~basic_transcoder_file()
inline constexpr ~basic_transcoder_file()
{
this->transhandle->destroy();
}
Expand Down
Loading

0 comments on commit adf1ecd

Please sign in to comment.