Thread overview | ||||||
---|---|---|---|---|---|---|
|
February 05, 2021 Ugly c++ syntax | ||||
---|---|---|---|---|
| ||||
Can some C++ guru translate in D the template below? I gave up after reading a lot, but I didn't manage to understand the meaning "&& ..." template <typename...Tables> static uint8_t composite_index_size(Tables const&... tables) { return (composite_index_size(tables.size(), impl::bits_needed(sizeof...(tables))) && ...) ? 2 : 4; } Thanks. |
February 05, 2021 Re: Ugly c++ syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rumbu | On 2/5/21 1:10 PM, Rumbu wrote: > I gave up after reading a lot, but I didn't manage to understand the meaning "&& ..." I think it's the universal reference. > template <typename...Tables> static uint8_t composite_index_size(Tables const&... tables) { return (composite_index_size(tables.size(), impl::bits_needed(sizeof...(tables))) && ...) ? 2 : 4; } With some guesses, I made the following compile: import std.meta : staticMap; import std.algorithm : sum; ubyte composite_index_size(tables...)() { return (composite_index_size(tables.length, bits_needed(staticMap!(SizeOf, typeof(tables))))) ? 2 : 4; } auto composite_index_size(size_t count, size_t total) { return 42; } enum SizeOf(T) = T.sizeof; auto bits_needed(size_t[] args...) { return args.sum; } void main() { int[] i; double[] d; pragma(msg, composite_index_size!(i, d)); } Ali |
February 06, 2021 Re: Ugly c++ syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Saturday, 6 February 2021 at 00:35:12 UTC, Ali Çehreli wrote: > On 2/5/21 1:10 PM, Rumbu wrote: > >> I gave up after reading a lot, but I didn't manage to understand the meaning "&& ..." > > I think it's the universal reference. Thank you Ali, but nope, it's "parameter pack folding". This allows starting with C++ 17 to have recursive templates in one liner. Basically, it means "&& template(the rest of arguments)" https://github.com/microsoft/cppwin32/blob/8a6b2507734dd9e9892059b5794f35109688fc20/cppwin32/winmd/impl/winmd_reader/database.h#L490 |
February 06, 2021 Re: Ugly c++ syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rumbu | On Friday, 5 February 2021 at 21:10:21 UTC, Rumbu wrote:
> Can some C++ guru translate in D the template below?
>
> I gave up after reading a lot, but I didn't manage to understand the meaning "&& ..."
>
> template <typename...Tables> static uint8_t composite_index_size(Tables const&... tables) { return (composite_index_size(tables.size(), impl::bits_needed(sizeof...(tables))) && ...) ? 2 : 4; }
>
> Thanks.
modern cpp looks like 10 lines of decl for 1 of actual code.
|
Copyright © 1999-2021 by the D Language Foundation