Ugly c++ syntax

Ali Çehreli acehreli at yahoo.com
Sat Feb 6 00:35:12 UTC 2021


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


More information about the Digitalmars-d-learn mailing list