Skip to content

Commit

Permalink
Merge pull request #1 from cppfastio/master
Browse files Browse the repository at this point in the history
  • Loading branch information
havedifficultyinfindingnames committed Jan 30, 2023
2 parents bd883da + 2ad387b commit d682811
Show file tree
Hide file tree
Showing 68 changed files with 1,143 additions and 899 deletions.
10 changes: 10 additions & 0 deletions benchmark/0007.concat/concat_vs_format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <fmt/compile.h>
#endif
#endif
#include<sstream>

struct benchmark_return
{
Expand Down Expand Up @@ -47,6 +48,13 @@ inline std::string color_concat(std::uint_least8_t r,std::uint_least8_t g,std::u
return fast_io::concat("Red: ",r,", Green: ",g,", Blue: ",b);
}

inline std::string color_ostringstream(std::uint_least8_t r,std::uint_least8_t g,std::uint_least8_t b)
{
std::ostringstream oss;
oss<<"Red: "<<r<<", Green: "<<g<<", Blue: "<<b;
return std::move(oss.str());
}

#if __has_include(<fmt/core.h>) && defined(ENABLE_FMT_BENCH)

inline std::string color_fmt_format(std::uint_least8_t r,std::uint_least8_t g,std::uint_least8_t b)
Expand All @@ -70,6 +78,7 @@ int main()
auto format_time = benchmark(color_format);
#endif
auto concat_time = benchmark(color_concat);
auto ostringstream_time = benchmark(color_ostringstream);
#if __has_include(<fmt/core.h>) && defined(ENABLE_FMT_BENCH)
auto fmt_format_time = benchmark(color_fmt_format);
#if __has_include(<fmt/compile.h>)
Expand All @@ -82,6 +91,7 @@ int main()
"std::format (total size:",format_time.total_size,") took ",format_time.timestamp,"s.\n"
#endif
"fast_io::concat (total size: ",concat_time.total_size,") took ",concat_time.timestamp,"s.\n"
"std::ostringstream (total size: ",ostringstream_time.total_size,") took ",ostringstream_time.timestamp,"s.\n"
#if __has_include(<fmt/core.h>) && defined(ENABLE_FMT_BENCH)
"fmt::format (total size:",fmt_format_time.total_size,") took ",fmt_format_time.timestamp,"s.\n"
#if __has_include(<fmt/compile.h>)
Expand Down
12 changes: 12 additions & 0 deletions examples/0007.legacy/filebuf_file_ostream.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include<fast_io_legacy.h>

int main()
{
fast_io::filebuf_file fbf(u8"filebuf_file_ostream.txt",fast_io::open_mode::out);
/*
filebuf_file will construct a std::filebuf directly through syscalls.
*/
std::ostream fout(fbf.fb); //make std::ostream's streambuf binds to our filebuf_file
print(fbf,"Hello World from fast_io::filebuf_file\n");
fout<<"Hello World from std::ostream\n";
}
2 changes: 1 addition & 1 deletion examples/0020.operating_system/limine/kernel/kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void _start(struct stivale2_struct *stivale2_struct) noexcept
auto& epoch{stivale2_get<stivale2_struct_tag_epoch>(stivale2_struct, STIVALE2_STRUCT_TAG_EPOCH_ID)};
fast_io::unix_timestamp tsp{static_cast<std::int_least64_t>(epoch.epoch)};
println(console,u8"Hello fast_io Kernel: stivale2_struct address:",stivale2_struct,u8"\n"
u8"Unix Tiemstamp:",tsp,u8"\n"
u8"Unix Timestamp:",tsp,u8"\n"
u8"UTC:",utc(tsp));

// We're done, just hang...
Expand Down
18 changes: 9 additions & 9 deletions include/fast_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#pragma warning( disable : 4514 )
#endif

#if __STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)
#if ((__STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)) || defined(FAST_IO_ENABLE_HOSTED_FEATURES))
#if __has_include(<stdio.h>)
#include"fast_io_legacy_impl/c/impl.h"
#endif
Expand Down Expand Up @@ -251,9 +251,9 @@ static_assert(type_error,"some types are not printable for print");
}
else
{
#if __STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING) && __has_include(<stdio.h>)
#if ((__STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)) || defined(FAST_IO_ENABLE_HOSTED_FEATURES)) && __has_include(<stdio.h>)
constexpr bool type_error{::fast_io::print_freestanding_okay<
#if __has_include(<stdio.h>)
#if __has_include(<stdio.h>)
::fast_io::c_io_observer
#else
::fast_io::native_io_observer
Expand Down Expand Up @@ -291,7 +291,7 @@ static_assert(type_error,"some types are not printable for println");
}
else
{
#if __STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING) && __has_include(<stdio.h>)
#if ((__STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)) || defined(FAST_IO_ENABLE_HOSTED_FEATURES)) && __has_include(<stdio.h>)
constexpr bool type_error{::fast_io::print_freestanding_okay<
#if __has_include(<stdio.h>)
::fast_io::c_io_observer
Expand Down Expand Up @@ -331,7 +331,7 @@ static_assert(type_error,"some types are not printable for perr");
}
else
{
#if __STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)
#if ((__STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)) || defined(FAST_IO_ENABLE_HOSTED_FEATURES))
constexpr bool type_error{::fast_io::print_freestanding_okay<
#if defined(__AVR__)
::fast_io::c_io_observer
Expand Down Expand Up @@ -371,7 +371,7 @@ static_assert(type_error,"some types are not printable for perrln");
}
else
{
#if __STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)
#if ((__STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)) || defined(FAST_IO_ENABLE_HOSTED_FEATURES))
constexpr bool type_error{::fast_io::print_freestanding_okay<
#if defined(__AVR__)
::fast_io::c_io_observer
Expand Down Expand Up @@ -448,7 +448,7 @@ static_assert(type_error,"some types are not printable for debug_print");
}
else
{
#if __STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)
#if ((__STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)) || defined(FAST_IO_ENABLE_HOSTED_FEATURES))
constexpr bool type_error{::fast_io::print_freestanding_okay<
#if defined(__AVR__)
::fast_io::c_io_observer
Expand Down Expand Up @@ -488,7 +488,7 @@ static_assert(type_error,"some types are not printable for debug_println");
}
else
{
#if __STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)
#if ((__STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)) || defined(FAST_IO_ENABLE_HOSTED_FEATURES))
constexpr bool type_error{::fast_io::print_freestanding_okay<
#if defined(__AVR__)
::fast_io::c_io_observer
Expand Down Expand Up @@ -542,7 +542,7 @@ inline constexpr std::conditional_t<report,bool,void> scan(input&& in,Args&& ...
}
else
{
#if __STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING) && __has_include(<stdio.h>)
#if ((__STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)) || defined(FAST_IO_ENABLE_HOSTED_FEATURES)) && __has_include(<stdio.h>)
return fast_io::details::scan_after_io_scan_forward<report>(fast_io::io_scan_forward<char>(fast_io::io_scan_alias(in)),fast_io::io_scan_forward<char>(fast_io::io_scan_alias(args))...);
#else
static_assert(fast_io::input_stream<std::remove_cvref_t<input>>,"freestanding environment must provide IO device");
Expand Down
2 changes: 1 addition & 1 deletion include/fast_io_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
#include"fast_io_core_impl/simd_find.h"
#include"fast_io_core_impl/integers/sto/sto_contiguous.h"

#if !(defined(FAST_IO_DISABLE_CODECVT)&&(__STDC_HOSTED__==0 || (defined(_GLIBCXX_HOSTED) && _GLIBCXX_HOSTED==0)))
#ifndef FAST_IO_DISABLE_CODECVT
#include"fast_io_core_impl/codecvt/impl.h"
#endif
#include"fast_io_core_impl/io_deco_ref.h"
Expand Down
8 changes: 1 addition & 7 deletions include/fast_io_core_impl/alias.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ inline constexpr auto io_print_forward(T&& t) noexcept
using no_cvref_t=std::remove_cvref_t<T>;
if constexpr(status_io_print_forwardable<char_type,T>)
return status_io_print_forward(io_alias_type<char_type>,::std::forward<T>(t));
else if constexpr(std::is_trivially_copyable_v<no_cvref_t>&&sizeof(no_cvref_t)<=
#if (defined(_WIN32)&&!defined(__WINE__)) || defined(__CYGWIN__)
8
#else
sizeof(std::size_t)*2
#endif
)
else if constexpr(std::is_trivially_copyable_v<no_cvref_t>&&sizeof(no_cvref_t)<=sizeof(std::size_t)*2)
return static_cast<no_cvref_t>(t);
else
return parameter<std::remove_reference_t<T> const&>{t};
Expand Down
5 changes: 2 additions & 3 deletions include/fast_io_core_impl/allocation/impl.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#pragma once

#if __STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)

#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(__WINE__)
#include"win32_heapalloc.h"
#include"nt_rtlheapalloc.h"
#if defined(_MSC_VER) && !defined(__clang__)
#include"msvc/impl.h"
#endif
#endif
#if ((__STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)) || defined(FAST_IO_ENABLE_HOSTED_FEATURES))
#include"c_malloc.h"
#endif

Expand All @@ -34,7 +33,7 @@ custom_global_allocator
mimalloc_allocator
#elif (defined(__linux__) && defined(__KERNEL__)) || defined(FAST_IO_USE_LINUX_KERNEL_ALLOCATOR)
linux_kmalloc_allocator
#elif __STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)
#elif ((__STDC_HOSTED__==1 && (!defined(_GLIBCXX_HOSTED) || _GLIBCXX_HOSTED==1) && !defined(_LIBCPP_FREESTANDING)) || defined(FAST_IO_ENABLE_HOSTED_FEATURES))
#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WINE__) && !defined(FAST_IO_USE_C_MALLOC)
win32_heapalloc_allocator
#else
Expand Down
9 changes: 9 additions & 0 deletions include/fast_io_core_impl/codecvt/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,15 @@ constexpr auto code_cvt(basic_io_scatter_t<char_type> t) noexcept
return code_cvt_t<src_scheme,dst_scheme,char_type>{t};
}

template<
encoding_scheme src_scheme=encoding_scheme::execution_charset,
encoding_scheme dst_scheme=encoding_scheme::execution_charset,
std::integral char_type,std::size_t N>
constexpr auto code_cvt(small_scatter_t<char_type,N> t) noexcept
{
return code_cvt_t<src_scheme,dst_scheme,char_type>{{t.base,t.len}};
}

template<
encoding_scheme src_scheme=encoding_scheme::execution_charset,
encoding_scheme dst_scheme=encoding_scheme::execution_charset,
Expand Down
68 changes: 1 addition & 67 deletions include/fast_io_core_impl/codecvt/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,78 +16,12 @@ inline constexpr auto status_io_print_forward(io_alias_type_t<char_type>,cross_c
{
if constexpr(std::same_as<char_type,cross_char_type>)
{
#if 0
constexpr bool is_windows{
#if (defined(_WIN32)&&!defined(__WINE__)) || defined(__CYGWIN__)
true
#else
false
#endif
};
if constexpr(is_windows&&sizeof(std::size_t)==sizeof(std::uint_least64_t))
{
return parameter<basic_io_scatter_t<char_type> const&>{ccvt.scatter};
}
else
#endif
{
return ccvt.scatter;
}
return ccvt.scatter;
}
else
{
return ::fast_io::mnp::code_cvt_t<encoding_scheme::execution_charset,encoding_scheme::execution_charset,cross_char_type>{ccvt.scatter};
}
}

namespace manipulators
{

template<::fast_io::details::character char_type>
inline constexpr cross_code_cvt_t<char_type> os_env(int argc,char_type const** argv,std::size_t n) noexcept
{
if(argc<=0)[[unlikely]]
{
if(n==0)
{
if constexpr(std::same_as<char_type,char>)
{
return {{"",0}};
}
else if constexpr(std::same_as<char_type,wchar_t>)
{
return {{L"",0}};
}
else if constexpr(std::same_as<char_type,char16_t>)
{
return {{u"",0}};
}
else if constexpr(std::same_as<char_type,char16_t>)
{
return {{u"",0}};
}
else
{
return {{u8"",0}};
}
}
else
{
::fast_io::fast_terminate();
}
}
else
{
std::size_t argcsz{static_cast<std::size_t>(argc)};
if(argcsz<=n)[[unlikely]]
{
::fast_io::fast_terminate();
}
}
auto cstr{argv[n]};
return {{cstr,::fast_io::cstr_len(cstr)}};
}

}

}
7 changes: 7 additions & 0 deletions include/fast_io_core_impl/concepts/details.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ concept buffer_output_stream_impl = requires(T&& out,typename std::remove_cvref_
obuffer_overflow(out,ch);
};

template<typename T>
concept constant_buffer_output_stream_impl = requires(T&& out)
{
{obuffer_constant_size(io_reserve_type<typename std::remove_cvref_t<T>::char_type,std::remove_cvref_t<decltype(out)>>)}->std::same_as<std::size_t>;
obuffer_constant_flush_prepare(out);
};

template<typename T>
concept flush_output_stream_impl = requires(T&& out)
{
Expand Down
3 changes: 3 additions & 0 deletions include/fast_io_core_impl/concepts/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ concept contiguous_input_stream = buffer_input_stream<T>&&details::contiguous_in
template<typename T>
concept buffer_output_stream = output_stream<T>&&details::buffer_output_stream_impl<T>;

template<typename T>
concept constant_buffer_output_stream = buffer_output_stream<T>&&details::constant_buffer_output_stream_impl<T>;

template<typename T>
concept contiguous_output_stream = buffer_output_stream<T>&&details::contiguous_output_stream_impl<T>;

Expand Down
4 changes: 2 additions & 2 deletions include/fast_io_core_impl/freestanding/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,13 @@ inline constexpr ForwardIt lower_bound(ForwardIt first, ForwardIt last, T const&
{
ForwardIt it;
typename ::std::iterator_traits<ForwardIt>::difference_type count, step;
count = std::distance(first, last);
count = last-first;

while (count > 0)
{
it = first;
step = count / 2;
std::advance(it, step);
it+= step;

if (comp(*it, value))
{
Expand Down
2 changes: 1 addition & 1 deletion include/fast_io_core_impl/integers/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ inline constexpr char_type* print_reserve_nullptr_alphabet_impl(char_type* iter)
}

template<typename scalar_type>
requires (details::my_integral<scalar_type>||std::is_pointer_v<std::remove_cvref_t<scalar_type>>||::std::contiguous_iterator<scalar_type>||::fast_io::details::my_floating_point<scalar_type>||std::same_as<std::nullptr_t,std::remove_cvref_t<scalar_type>>)
requires (details::my_integral<scalar_type>||(std::is_pointer_v<std::remove_cvref_t<scalar_type>>)||::std::contiguous_iterator<scalar_type>||::fast_io::details::my_floating_point<scalar_type>||std::same_as<std::nullptr_t,std::remove_cvref_t<scalar_type>>)
#if __has_cpp_attribute(__gnu__::__always_inline__)
[[__gnu__::__always_inline__]]
#elif __has_cpp_attribute(msvc::forceinline)
Expand Down
Loading

0 comments on commit d682811

Please sign in to comment.