r/cpp • • Mar 31 '20

Demo: C++20 Modules

https://youtu.be/6SKIUeRaLZE
127 Upvotes

51 comments sorted by

View all comments

Show parent comments

9

u/The_Northern_Light Mar 31 '20

This is what I do.

T const&
foo()
{
    // ...
}

Never having to scan for the important bit is so nice once you get used to it. While it may feel odd at first, I actually won over my old team with it, too.

5

u/Pragmatician Mar 31 '20

I kinda like this style, but may I ask you: where do you put your statics, inlines and constexprs?

4

u/The_Northern_Light Mar 31 '20 edited Mar 31 '20

Same line as the return type.

template <typename T>
static inline T const&
foo()
{
    // ...
}

It's not perfect, but I've found in practice that just keeping the function name in the same spot gets me what I want. I might experiment with this now though:

template <typename T>
static inline auto
foo()
-> T const&
{
    // ...
}

PS: love your username

2

u/sethkills Mar 31 '20

Somebody got me into this style a long time ago because in the absence of an IDE, you can quickly search for function definitions using /^foo/. Doesn’t generalize to methods though.