r/cpp • • Mar 30 '15

Simple Question

So I was thinking the other day, and I came up with an idea that I decided to try... a function returning an anonymous struct!

I tried it, and lo and behold, it doesn't compile. A closer look reveals that the Standard specifically disallows defining new types as the return type of a function definition! Though it does appear that I can return an anonymous struct using decltype, that is even more code than simply defining a new type name.

My Simple Question is... why? What reason did the standards committee have to explicitly disallow this? Is this a case of them trying to save users from their own stupidity, or is this technically infeasible somehow?

1 Upvotes

20 comments sorted by

View all comments

3

u/STL MSVC STL Dev Mar 31 '15

The language is so complicated already. That complexity buys a lot of power, but additional complexity must be worth it. What you're talking about, wouldn't.

Think of it like microprocessor design. These days, they won't add features that increase power consumption by 1%, unless they also increase performance by at least 2%.

Or as I would say as an STL maintainer, "if you want tuple, you know where to find it".

1

u/[deleted] Jun 11 '15

The language is so complicated already

Agreed, so much indeed that the feature is already in the language: http://ideone.com/Ir1Hpu