Perfect Forwarding with Template

By writing a constructor template you can cover several alternatives of the constructors.

But there is also a way to call copy constructor or move constructor when you forwarding an object.

In flowing code, we provided a Has-A type class to understand what type of constructor called.

In the Has-A class, we implemented 4 types of initialization 2 for copy and 2 for the move. You may mention that std::mode has been used to forward parameter without creating a copy of it.

Template method have been used on the MyClass Class and it uses std:: forward method.

std::forward is a template method which looks the type of typetypes. If the type of the template is a reference type, it creates a copy of the object, otherwise moves the object.

You may also like...

1 Response

  1. 2020-03-15

    […] option is reading. Yes, it is a very new blog I know but if you want you can read my post such as Perfect Forwarding with Template to dive in C++11/14-17 or […]

Leave a Reply

Your email address will not be published. Required fields are marked *