Skip to content
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
117 changes: 78 additions & 39 deletions examples/0003.manipulators/pointer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct A
virtual void f() noexcept
{}
};

struct B
{
virtual void g() noexcept
Expand All @@ -23,59 +24,97 @@ struct C : A, B
{
};

struct S
{
int x;
double y;
int z;
};

struct VA
{
int a;
};

struct VB : virtual VA
{
int b;
};

using namespace fast_io::io;

void foo(){}
void foo()
{}

int main()
{
using namespace fast_io::mnp;

int fd{3};
int *ptr{::std::addressof(fd)};

char const *ptr2 = "hello";

void (C::*downcptr)() noexcept = &B::g;

println("funcvw(foo):", funcvw(foo),
"\n"
"pointervw(ptr):",
pointervw(ptr),
"\n"
"handlevw(fd):",
handlevw(fd),
"\n"
"handlevw(ptr):",
handlevw(ptr),
"\n"
"pointervw(ptr2):",
pointervw(ptr2),
"\n"
"dec(pointervw(ptr2)):",
dec(pointervw(ptr2)),
"\n"
"os_c_str(ptr2):",
os_c_str(ptr2),
"\n"
"methodvw(&dummy_class::dummy_method):",
methodvw(&dummy_class::dummy_method),
"\n"
"dec(methodvw(&dummy_class::dummy_method)):",
dec(methodvw(&dummy_class::dummy_method)),
"\n"
"methodvw(downcptr):",
methodvw(downcptr));
println(
"funcvw(foo):", funcvw(foo),
"\n"
"pointervw(ptr):",
pointervw(ptr),
"\n"
"handlevw(fd):",
handlevw(fd),
"\n"
"handlevw(ptr):",
handlevw(ptr),
"\n"
"pointervw(ptr2):",
pointervw(ptr2),
"\n"
"dec(pointervw(ptr2)):",
dec(pointervw(ptr2)),
"\n"
"os_c_str(ptr2):",
os_c_str(ptr2),
"\n"
"methodvw(&dummy_class::dummy_method):",
methodvw(&dummy_class::dummy_method),
"\n"
"dec(methodvw(&dummy_class::dummy_method)):",
dec(methodvw(&dummy_class::dummy_method)),
"\n"
"methodvw(downcptr):",
methodvw(downcptr),
"\n"
"fieldptrvw(&S::x):",
fieldptrvw(&S::x),
"\n"
"fieldptrvw(&S::y):",
fieldptrvw(&S::y),
"\n"
"fieldptrvw(&S::z):",
fieldptrvw(&S::z),
"\n"
"fieldptrvw(&VB::b):",
fieldptrvw(&VB::b),
"\n"
"fieldptrvw(&VA::a):",
fieldptrvw(&VA::a));
}

/*
funcvw(foo):0x00007ff75abf27c0
pointervw(ptr):0x000000c232d0fa9c
funcvw(foo):0x0000000102368570
pointervw(ptr):0x000000016da96e1c
handlevw(fd):3
handlevw(ptr):0x000000c232d0fa9c
pointervw(ptr2):0x00007ff75abf4540
dec(pointervw(ptr2)):140700356134208
handlevw(ptr):0x000000016da96e1c
pointervw(ptr2):0x0000000102369f0c
dec(pointervw(ptr2)):4332101388
os_c_str(ptr2):hello
methodvw(&dummy_class::dummy_method):0x00007ff75abf34b0+0x0
dec(methodvw(&dummy_class::dummy_method)):140700356129968+0
methodvw(downcptr):0x0000000000000001+0x8
methodvw(&dummy_class::dummy_method):0x0000000102369400+0x0
dec(methodvw(&dummy_class::dummy_method)):4332098560+0
methodvw(downcptr):0x0000000000000000+0x11
fieldptrvw(&S::x):0x0000000000000000
fieldptrvw(&S::y):0x0000000000000008
fieldptrvw(&S::z):0x0000000000000010
fieldptrvw(&VB::b):0x0000000000000008
fieldptrvw(&VA::a):0x0000000000000000
*/
26 changes: 26 additions & 0 deletions include/fast_io_core_impl/integers/impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,32 @@ inline constexpr auto funcvw(scalar_type *t) noexcept
::fast_io::details::base_mani_flags_cache<16, uppercase, true, true, false>>(::std::bit_cast<::std::size_t>(t));
}

template <bool uppercase = false, typename scalar_type>
requires(::std::is_member_object_pointer_v<scalar_type>)
inline constexpr auto fieldptrvw(scalar_type t) noexcept
{
if constexpr (sizeof(t) == sizeof(::fast_io::manipulators::member_function_pointer_holder_t))
{
return ::fast_io::details::scalar_flags_int_cache<
::fast_io::details::base_mani_flags_cache<16, uppercase, true, true, false>>(
::std::bit_cast<::fast_io::manipulators::member_function_pointer_holder_t>(t));
}
else
{
using equivalentsizetype = ::std::conditional_t<
sizeof(scalar_type) == sizeof(::std::size_t), ::std::size_t,
::std::conditional_t<sizeof(scalar_type) == sizeof(::std::uint_least64_t),
::std::uint_least64_t,
::std::conditional_t<sizeof(scalar_type) == sizeof(::std::uint_least32_t),
::std::uint_least32_t,
::std::conditional_t<sizeof(scalar_type) == sizeof(::std::uint_least16_t),
::std::uint_least16_t,
::std::uint_least8_t>>>>;
return ::fast_io::details::scalar_flags_int_cache<
::fast_io::details::base_mani_flags_cache<16, uppercase, true, true, false>>(::std::bit_cast<equivalentsizetype>(t));
}
}

template <bool uppercase = false, typename scalar_type>
requires(::std::is_member_function_pointer_v<scalar_type> && (sizeof(scalar_type) % sizeof(::std::size_t) == 0))
inline constexpr auto methodvw(scalar_type t) noexcept
Expand Down
2 changes: 1 addition & 1 deletion include/fast_io_hosted/threads/thread/wasi.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ inline
#endif
void yield() noexcept
{
__wasi_sched_yield();
(void)__wasi_sched_yield();
}

} // namespace this_thread
Expand Down
28 changes: 28 additions & 0 deletions tests/0011.manipulators/fieldptrvw.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <fast_io.h>

struct S
{
int x;
double y;
int z;
};
struct A
{
int a;
};
struct B
{
int b;
};
struct C : A, B
{}; // multiple inheritance

int main()
{
using namespace ::fast_io::iomnp;
println("&B::b = ", fieldptrvw(&B::b), "\n"
"&C::b = ",
fieldptrvw(&C::b), "\n"
"&S::z = ",
fieldptrvw(&S::z));
}