Search code examples
c++default-constructordecltypetemporarydeclval

Zero Initialize a Type


Given a variable of an unsigned integral type: foo lets say I want to do this:

const decltype<foo> bar{};

cout << (55834574890LL & ~bar) << endl;

That gives me the expected 42. But now let's say that I want to do away with the bar variable. So something like this:

cout << (55834574890LL & ~decltype<foo>{}) << endl;

But I just get an error:

error: expected primary-expression before decltype

I've also tried declval but that returns a reference, which is also no good. Is there a way I can do this?


Solution

  • You should use round brackets:

    auto v = 55834574890LL & ~decltype(foo){};
    

    Here's a demo.