Fix sir::is_custom

This commit is contained in:
Nikita Lisitsa 2023-08-15 11:47:43 +03:00
parent 67c7ce0878
commit 1036ebae30

View file

@ -5,41 +5,41 @@
#include <type_traits>
namespace psemek_sir_adl_helper
{
struct fake_istream
{
void read(char *, std::size_t){}
std::size_t offset() const { return 0; }
};
struct fake_ostream
{
void write(char const *, std::size_t){}
std::size_t offset() const { return 0; }
};
static_assert(::psemek::sir::is_istream_v<fake_istream>);
static_assert(::psemek::sir::is_ostream_v<fake_ostream>);
template <typename T>
constexpr bool is_custom_helper = requires (T & x, fake_istream & is, fake_ostream & os)
{
write(os, x);
read(is, x);
};
}
namespace psemek::sir
{
namespace detail
{
struct fake_istream
{
void read(char *, std::size_t){}
std::size_t offset() const { return 0; }
};
struct fake_ostream
{
void write(char const *, std::size_t){}
std::size_t offset() const { return 0; }
};
static_assert(is_istream_v<fake_istream>);
static_assert(is_ostream_v<fake_ostream>);
template <typename T>
constexpr bool is_custom_helper = requires (T & x, fake_istream & is, fake_ostream & os)
{
write(os, x);
read(is, x);
};
}
template <typename T>
struct is_custom
: std::bool_constant<detail::is_custom_helper<T>>
: std::bool_constant<::psemek_sir_adl_helper::is_custom_helper<T>>
{};
template <typename T>
@ -55,7 +55,7 @@ namespace psemek::sir
template <typename T>
struct is_trivial
: std::bool_constant<std::is_trivial_v<T> && std::is_standard_layout_v<T>>
: std::bool_constant<std::is_trivially_default_constructible_v<T> && std::is_trivially_copyable_v<T> && std::is_standard_layout_v<T>>
{};
template <typename T>