1

I stumbled over a piece of syntax that I have not seen yet and didn't find online, and I wonder what this is:

constexpr struct X{ /* define X members and methods */ } Y{};

What i don't understand is the Y{}.

nnolte
  • 1,628
  • 11
  • 25
  • which part you dont understand? One could write a full article about that single line covering c-heritage up to latest c++ features. – 463035818_is_not_an_ai Jun 08 '18 at 09:40
  • What is `something`? What does it look like? – miravalls Jun 08 '18 at 09:44
  • 3
    `struct X{ /* something here */}` defines a struct `constexpr Y` creates that struct that's a compile time constant called Y `{};` initialises the values in the struct – UKMonkey Jun 08 '18 at 09:44
  • 1
    @UKMonkey I'd make your comment an answer and link to another question that asks about list initialization. Maybe these questions help: https://stackoverflow.com/questions/41212130/understanding-the-weird-syntax-with-curly-braces-in-a-constructor-initializer-li/41212196 https://stackoverflow.com/questions/18222926/why-is-list-initialization-using-curly-braces-better-than-the-alternatives. – miravalls Jun 08 '18 at 09:47
  • ref. [`constexpr`](https://en.cppreference.com/w/cpp/language/constexpr) – Sander De Dycker Jun 08 '18 at 09:48

1 Answers1

2
constexpr struct X{ /* something here */} Y{};

is equal to

struct X{ /* something here */};

constexpr X Y{};

For constexpr, check this documentation.

DeiDei
  • 10,205
  • 6
  • 55
  • 80