Похожие чаты

Is there any way to print like this using loops

?
The sizeof(char) is : 1 bytes
The sizeof(short) is : 2 bytes
The sizeof(int) is : 4 bytes
The sizeof(long) is : 8 bytes
The sizeof(long long) is : 8 bytes
The sizeof(float) is : 4 bytes
The sizeof(double) is : 8 bytes
The sizeof(long double) is : 16 bytes
The sizeof(bool) is : 1 bytes

5 ответов

6 просмотров

I don't think there's a way to iterate over types using loops, you can use variadic templates, but they are really limited, maybe some variadic macros can do that (or combination of variadic mactos and variadic templates), but the solution will probably be super ugly. Here's an example of using variadic templates, note that string representation of the type is compiler-specific (different compilers can print different things) https://wandbox.org/permlink/rkRVPf9y1ywaDHKa

Pavel
I don't think there's a way to iterate over types ...

probably the cleanest way of doing that is with a macro

Nomid Íkorni-Sciurus Lomysz
probably the cleanest way of doing that is with a ...

i doubt it would be of any cleaner, you'll have to define recursive macros which will be more cumbersome then just doing straight up print statements with the different types.

Pavel
I don't think there's a way to iterate over types ...

Using the Boost.TypeIndex: www.boost.org/doc/libs/1_78_0/doc/html/boost_typeindex/examples.html with the variadic function could be good.

Похожие вопросы

Обсуждают сегодня

Ясн. Но я всеравно к кедам отношусь с опасением. Чисто субьективное кедосозерцание. Что касаемо "восторга изяшности кед" так и не вкурил, хотя много слышал, пока не поставил с...
Артем Записной
30
They keep hyping $FUN but where's the progress? 🙄
Noah Noure
23
Btw guys very stupid question but i haven't researchd so js asking you pros . Can ltc be traced too? Literally point to pint to the user? And getting the banks blocked ? Exch...
20
type TObj = object procedure Init; virtual; end; TObj1 = object(TObj) procedure Init; override; end; procedure TObj1.Init; begin inherited; end; procedur...
Alexander 👋
29
Есть какой-нибудь для Delphi/FPC T*Compression(Decompression)Stream на базе LZ4/Zstd/любой другой быстрый(и хорошо сжимающий) алгоритм А ещё лучше в pure pascal А ещё лучше од...
notme
48
А чем вам питонисты не угодили?😂
.
79
Hey guys, did you see the new announcement about $Fun? 🔥
Filip Murphy
55
How can a minority hashrate chain defend from a fork-hopping ASIC miner? The problem: 1. A miner comes into your network, and mines at 60-70% hashrate. 2. After some time, th...
Kishniev
13
yeap, thanks guys for response, but I really like to understand does a pool created on curve.fi has the option or api or I can call a function of a smart contract to set excha...
Oleg Karoza
11
Hey people, how do I unstake from the old pool and stake in the new pool??
Dyldo Baggins
24
Карта сайта