Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue with libstdc++ that incorrectly deals with C++11 string not… #7

Merged
merged 1 commit into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions include/fast_io_core_impl/integers/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -954,18 +954,12 @@ constexpr Iter print_reserve_integral_withfull_main_impl(Iter first,T u)
template<std::size_t base,bool uppercase,::fast_io::freestanding::random_access_iterator Iter,my_unsigned_integral T>
inline constexpr void print_reserve_integral_withfull_precise_main_impl(Iter last,T u,std::size_t n)
{

if constexpr(sizeof(u)<=sizeof(unsigned)&&sizeof(unsigned)<=sizeof(std::size_t))
print_reserve_integral_main_impl<base,uppercase>(last,static_cast<unsigned>(u),n);
else
{
if constexpr(sizeof(std::size_t)<sizeof(u))
{

}
else
{
print_reserve_integral_main_impl<base,uppercase>(last,u,n);
}
print_reserve_integral_main_impl<base,uppercase>(last,u,n);
}
}

Expand Down Expand Up @@ -1114,11 +1108,22 @@ constexpr void print_reserve_integral_define_precise(Iter start,std::size_t n,in
}
if constexpr(showbase&&(base!=10))
first=print_reserve_show_base_impl<base,uppercase_showbase>(first);
auto ed{start+n};
if constexpr(my_unsigned_integral<int_type>&&!showbase&&!showpos)
print_reserve_integral_withfull_precise_main_impl<base,uppercase>(ed,u,n);
if constexpr(::std::is_pointer_v<Iter>&&base==10&&(std::numeric_limits<std::uint_least32_t>::digits==32u))
{
return ::fast_io::details::jeaiii::jeaiii_main_len(first,u,static_cast<std::uint_least32_t>(n));
}
else if constexpr(::fast_io::freestanding::contiguous_iterator<Iter>&&base==10&&(std::numeric_limits<std::uint_least32_t>::digits==32u))
{
return ::fast_io::details::jeaiii::jeaiii_main_len(::fast_io::freestanding::to_address(first),u,static_cast<std::uint_least32_t>(n))-::fast_io::freestanding::to_address(first)+first;
}
else
print_reserve_integral_withfull_precise_main_impl<base,uppercase>(ed,u,static_cast<std::size_t>(ed-first));
{
auto ed{start+n};
if constexpr(my_unsigned_integral<int_type>&&!showbase&&!showpos)
print_reserve_integral_withfull_precise_main_impl<base,uppercase>(ed,u,n);
else
print_reserve_integral_withfull_precise_main_impl<base,uppercase>(ed,u,static_cast<std::size_t>(ed-first));
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion include/fast_io_freestanding.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(push)
#pragma warning( disable : 4514 )
#pragma warning( disable : 4554 )
#pragma warning( disable : 4668 )
#pragma warning( disable : 4820 )
#pragma warning( disable : 4710 )
#endif
Expand All @@ -28,7 +30,7 @@
#include"fast_io_freestanding_impl/io_buffer/impl.h"
#include"fast_io_freestanding_impl/naive_vector.h"
#include"fast_io_freestanding_impl/auto_indent.h"
#include"fast_io_freestanding_impl/lebe.h"
#include"fast_io_freestanding_impl/serializations/impl.h"
#include"fast_io_freestanding_impl/space_reserve.h"
#include"fast_io_freestanding_impl/width.h"
#include"fast_io_freestanding_impl/scanners/impl.h"
Expand Down
4 changes: 4 additions & 0 deletions include/fast_io_freestanding_impl/serializations/impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

#include"lebe.h"
#include"str_get.h"
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#pragma once
namespace fast_io::details
{

template<std::size_t sz>
inline constexpr bool supported_lebe_size{sz==8||sz==16||sz==32||sz==64};

}
namespace fast_io::manipulators
{

Expand All @@ -12,6 +18,13 @@ struct basic_lebe_get_integral
template<std::size_t sz,typename value_type>
struct basic_lebe_put_integral
{
#ifndef __INTELLISENSE__
#if __has_cpp_attribute(msvc::no_unique_address)
[[msvc::no_unique_address]]
#elif __has_cpp_attribute(no_unique_address)
[[no_unique_address]]
#endif
#endif
value_type value;
};

Expand All @@ -20,53 +33,46 @@ template<::std::endian end,typename value_type>
struct basic_lebe_get_put
{
using manip_tag = manip_tag_t;
#ifndef __INTELLISENSE__
#if __has_cpp_attribute(msvc::no_unique_address)
[[msvc::no_unique_address]]
#elif __has_cpp_attribute(no_unique_address)
[[no_unique_address]]
#endif
#endif
value_type reference;
};

template<::std::endian en,::std::size_t sz,::fast_io::details::my_integral int_type>
requires (!::std::is_const_v<int_type>
#if __cpp_lib_int_pow2 >= 202002L
&&(::std::has_single_bit(sz))
#endif
)
requires (!::std::is_const_v<int_type>&&::fast_io::details::supported_lebe_size<sz>)
inline constexpr auto lebe_get(int_type& t) noexcept
{
return basic_lebe_get_put<en,basic_lebe_get_integral<sz,int_type>>{{__builtin_addressof(t)}};
}

template<::std::size_t sz,::fast_io::details::my_integral int_type>
requires (!::std::is_const_v<int_type>
#if __cpp_lib_int_pow2 >= 202002L
&&(::std::has_single_bit(sz))
#endif
)
requires (!::std::is_const_v<int_type>&&::fast_io::details::supported_lebe_size<sz>)
inline constexpr auto le_get(int_type& t) noexcept
{
return basic_lebe_get_put<::std::endian::little,basic_lebe_get_integral<sz,int_type>>{{__builtin_addressof(t)}};
}

template<::std::size_t sz,::fast_io::details::my_integral int_type>
requires (!::std::is_const_v<int_type>
#if __cpp_lib_int_pow2 >= 202002L
&&(::std::has_single_bit(sz))
#endif
)
requires (!::std::is_const_v<int_type>&&::fast_io::details::supported_lebe_size<sz>)
inline constexpr auto be_get(int_type& t) noexcept
{
return basic_lebe_get_put<::std::endian::big,basic_lebe_get_integral<sz,int_type>>{{__builtin_addressof(t)}};
}

template<::std::endian en,::std::size_t sz,::fast_io::details::my_integral int_type>
#if __cpp_lib_int_pow2 >= 202002L
requires (::std::has_single_bit(sz))
#endif
requires ::fast_io::details::supported_lebe_size<sz>
inline constexpr auto lebe_put(int_type t) noexcept((::std::numeric_limits<::fast_io::details::my_make_unsigned_t<::std::remove_cvref_t<int_type>>>::digits)<=sz)
{
using uint_type = ::fast_io::details::my_make_unsigned_t<::std::remove_cvref_t<int_type>>;
uint_type u{static_cast<uint_type>(t)};
if constexpr(sz<(::std::numeric_limits<uint_type>::digits))
{
constexpr uint_type mx_value_halfm1{static_cast<uint_type>(static_cast<int_type>(1)<<static_cast<int_type>(sz-1))};
constexpr uint_type mx_value_halfm1{static_cast<uint_type>((static_cast<int_type>(1) << static_cast<int_type>(sz-1)))};
constexpr uint_type mx_value{static_cast<uint_type>(static_cast<uint_type>(mx_value_halfm1-static_cast<uint_type>(1))+mx_value_halfm1)};
if(u>mx_value)
throw_parse_code(::fast_io::parse_code::invalid);
Expand All @@ -80,18 +86,14 @@ inline constexpr auto lebe_put(int_type t) noexcept((::std::numeric_limits<::fas
}

template<::std::size_t sz,::fast_io::details::my_integral int_type>
#if __cpp_lib_int_pow2 >= 202002L
requires (::std::has_single_bit(sz))
#endif
requires ::fast_io::details::supported_lebe_size<sz>
inline constexpr auto le_put(int_type t) noexcept(noexcept(lebe_put<::std::endian::little,sz>(t)))
{
return lebe_put<::std::endian::little,sz>(t);
}

template<::std::size_t sz,::fast_io::details::my_integral int_type>
#if __cpp_lib_int_pow2 >= 202002L
requires (::std::has_single_bit(sz))
#endif
requires ::fast_io::details::supported_lebe_size<sz>
inline constexpr auto be_put(int_type t) noexcept(noexcept(lebe_put<::std::endian::big,sz>(t)))
{
return lebe_put<::std::endian::big,sz>(t);
Expand Down
124 changes: 124 additions & 0 deletions include/fast_io_freestanding_impl/serializations/str_get.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#pragma once

namespace fast_io
{

namespace manipulators
{

template<typename T>
struct basic_str_get_all
{
using manip_tag = manip_tag_t;
#ifndef __INTELLISENSE__
#if __has_cpp_attribute(msvc::no_unique_address)
[[msvc::no_unique_address]]
#elif __has_cpp_attribute(no_unique_address)
[[no_unique_address]]
#endif
#endif
T reference;
std::size_t n;
};

template<typename T>
inline constexpr auto str_get_all(T&& reference,std::size_t n) noexcept
{
return basic_str_get_all<decltype(io_strlike_ref(io_alias,reference))>{io_strlike_ref(io_alias,reference),n};
}

}

namespace details
{
struct str_get_all_context
{
bool coping{};
};

template<::fast_io::freestanding::forward_iterator Iter,typename T>
inline constexpr parse_result<Iter> scan_context_define_str_get_all_buffer_common_impl(Iter first,Iter last,
io_strlike_reference_wrapper<::fast_io::freestanding::iter_value_t<Iter>,T> output,std::size_t n)
{
auto bg{obuffer_begin(output)};
auto curr{obuffer_curr(output)};
std::size_t elements{static_cast<std::size_t>(curr-bg)};
std::size_t remain_characters{static_cast<std::size_t>(n-elements)};
std::size_t itdiff{static_cast<std::size_t>(last-first)};
std::size_t to_copy{remain_characters};
bool not_enough{itdiff<remain_characters};
if(not_enough)
{
to_copy=itdiff;
}
auto firstthen{first+to_copy};
non_overlapped_copy_n(first,to_copy,curr);
obuffer_set_curr(output,curr+to_copy);
return {firstthen,(not_enough?(parse_code::partial):(parse_code::ok))};
}

template<::fast_io::freestanding::forward_iterator Iter,typename T>
inline constexpr parse_result<Iter> scan_context_define_str_get_all_buffer_strlike_impl(Iter first,Iter last,
io_strlike_reference_wrapper<::fast_io::freestanding::iter_value_t<Iter>,T> output,std::size_t n,bool& ctx)
{
if(!ctx)
{
obuffer_set_curr(output,obuffer_begin(output));
strlike_reserve(io_strlike_type<::fast_io::freestanding::iter_value_t<Iter>,T>,*output.ptr,n);
ctx=true;
}
return scan_context_define_str_get_all_buffer_common_impl(first,last,output,n);
}

template<::fast_io::freestanding::forward_iterator Iter,typename T>
inline constexpr parse_result<Iter> scan_context_define_str_get_all_general_strlike_impl(Iter first,Iter last,
io_strlike_reference_wrapper<::fast_io::freestanding::iter_value_t<Iter>,T> output,
std::size_t n,::fast_io::details::basic_concat_buffer<::fast_io::freestanding::iter_value_t<Iter>>& ctx)
{
using char_type = ::fast_io::freestanding::iter_value_t<Iter>;
auto ret{scan_context_define_str_get_all_buffer_common_impl(first,last,io_strlike_ref(ctx),n)};
if(ret.code==parse_code::ok)
{
*output.ptr=strlike_construct_define(io_strlike_type<char_type,T>,ctx.buffer_begin,ctx.buffer_curr);;
}
return ret;
}
}

template<::std::integral char_type,typename T>
inline constexpr io_type_t<::std::conditional_t<::fast_io::buffer_strlike<char_type,T>,::fast_io::details::str_get_all_context,
::fast_io::details::basic_concat_buffer<char_type>>>
scan_context_type(io_reserve_type_t<char_type,
::fast_io::manipulators::basic_str_get_all<io_strlike_reference_wrapper<char_type,T>>>) noexcept
{
return {};
}

template<::fast_io::freestanding::forward_iterator Iter,typename ctxtype,typename T>
inline constexpr parse_result<Iter> scan_context_define(
io_reserve_type_t<::fast_io::freestanding::iter_value_t<Iter>,
::fast_io::manipulators::basic_str_get_all<io_strlike_reference_wrapper<::fast_io::freestanding::iter_value_t<Iter>,T>>>,
ctxtype& ctx,
Iter first,Iter last,
::fast_io::manipulators::basic_str_get_all<io_strlike_reference_wrapper<::fast_io::freestanding::iter_value_t<Iter>,T>> str)
{
if constexpr(::fast_io::buffer_strlike<::fast_io::freestanding::iter_value_t<Iter>,T>)
{
return ::fast_io::details::scan_context_define_str_get_all_buffer_strlike_impl(first,last,str.reference,str.n,ctx.coping);
}
else
{
return ::fast_io::details::scan_context_define_str_get_all_general_strlike_impl(first,last,str.reference,str.n,ctx);
}
}

template<std::integral char_type,typename ctxtype,typename T>
inline constexpr parse_code scan_context_eof_define(io_reserve_type_t<char_type,
::fast_io::manipulators::basic_str_get_all<io_strlike_reference_wrapper<char_type,T>>>,
ctxtype&,
::fast_io::manipulators::basic_str_get_all<io_strlike_reference_wrapper<char_type,T>>)
{
return parse_code::end_of_file;
}

}
Loading