
On Tue, Oct 5, 2010 at 3:20 PM, Matt Calabrese <rivorus@gmail.com> wrote:
I've been noticing that a lot of times in 0x code I've found it useful to create a very simple "auto function" macro that uses trailing return type syntax with decltype with 1-liner functions that automatically repeats the same expression in both the return type and the return statement.
#define AUTO_FUN( name, param_list, expression ) \ auto name param_list -> decltype( expression ) { return expression; }
It's very aggravating that C++-0x didn't include include a function definition syntax like this from the start. A large chunk of the functions I write are 1-liners so the problem you're describing certainly applies to me. I've been using the following syntax wherever feasible: auto f = //some lambda or De Bruijn Bind expression That solves the repetition problem, but the code looses resemblance to typical C++ at that point. Although your solution works well, I think it is incredibly inelegant when compared to a C++ language fix. Can't we solve this problem cleanly and quickly? I'd really hate to see heaps of AUTO_FUN code created while we wait 12 years for the improvement in C++ syntax. So, personally I would not like to see this in boost. I'd like to see a clean solution in all standards conforming compilers. David -- David Sankel Sankel Software www.sankelsoftware.com 585 617 4748 (Office)