Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sample code for 'Effective Modern C++'

91 views
Skip to first unread message

Bart Vandewoestyne

unread,
Apr 5, 2015, 4:42:45 PM4/5/15
to
Hello group,

I was one of the reviewers for Scott Meyers his 'Effective Modern C++' book. During the review process, I have created lots of sample code for the material from the book. I am currently revising that sample code and uploading it to my GitHub repository https://github.com/BartVandewoestyne/Effective-Modern-Cpp I have 27 out of the 42 items online already, and hope to add the remaining 15 soon. Feel free to contribute by sending me pull requests! Comments and suggestions are also highly appreciated!

I hope that this online code will help the EMC++ readers to get a hands-on feeling for the principles explained in the book. Feel free to play with this code as much as you like and spread the message!

Kind regards,
Bart

DeMarcus

unread,
Apr 9, 2015, 1:00:05 PM4/9/15
to
> Hello group,
>
> I was one of the reviewers for Scott Meyers his 'Effective Modern C++' book. During the review process, I have created lots of sample code for the material from the book. I am currently revising that sample code and uploading it to my GitHub repository https://github.com/BartVandewoestyne/Effective-Modern-Cpp I have 27 out of the 42 items online already, and hope to add the remaining 15 soon. Feel free to contribute by sending me pull requests! Comments and suggestions are also highly appreciated!
>
> I hope that this online code will help the EMC++ readers to get a hands-on feeling for the principles explained in the book. Feel free to play with this code as much as you like and spread the message!
>

One thing that might be out of scope for the book, but something that I
wanted to understand when I read it, was how std::forward /really/
works. In the book and the example code it only brings up the universal
reference T&& case. This is fine since I guess std::forward and T&& are
used together in 99% of the cases.

What I needed to understand was what happens if you have a template that
takes T and not T&&.

template<typename T>
class SomeClass
{
public:
SomeClass( T t )
{
someFnc( std::forward<T>( t ) );
}
}

int main()
{
int i = 10;
SomeClass<int&> sc( i );
return 0;
}

My conclusion was (I hope it's correct?) that std::forward always pass
along lvalue references and move everything else.

Thanks for a very well written book!

Best regards,
Daniel


Luca Risolia

unread,
Apr 14, 2015, 3:55:55 PM4/14/15
to
Il 09/04/2015 18:59, DeMarcus ha scritto:
> In the book and the example code it only brings up the universal
> reference T&& case.

I don't think so, see Item 28.

> What I needed to understand was what happens if you have a template that
> takes T and not T&&.

> template<typename T>
> class SomeClass
> {
> public:
> SomeClass( T t )
> {
> someFnc( std::forward<T>( t ) );
> }
> }
>
> int main()
> {
> int i = 10;
> SomeClass<int&> sc( i );
> return 0;
> }
>
> My conclusion was (I hope it's correct?) that std::forward always pass
> along lvalue references and move everything else.

Yes, more or less, as std::forward<T> does not really move anything.

0 new messages