aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/nrvo_by_default/rvo.cpp
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-10-25 05:25:12 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-10-25 05:25:12 +0300
commit4c0f75c2f634803d325f18df5f5a90f35905e3cc (patch)
tree1f7bd45aa827c74745f319b55adb0e4015413845 /nrvo_by_default/rvo.cpp
parentfix license text (diff)
downloadblog-4c0f75c2f634803d325f18df5f5a90f35905e3cc.tar.gz
blog-4c0f75c2f634803d325f18df5f5a90f35905e3cc.zip
add nrvo_by_default/
Diffstat (limited to 'nrvo_by_default/rvo.cpp')
-rw-r--r--nrvo_by_default/rvo.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/nrvo_by_default/rvo.cpp b/nrvo_by_default/rvo.cpp
new file mode 100644
index 0000000..f8c8f32
--- /dev/null
+++ b/nrvo_by_default/rvo.cpp
@@ -0,0 +1,73 @@
+#include <iostream>
+#include <utility>
+
+namespace
+{
+ class C
+ {
+ public:
+ explicit C()
+ {
+ std::cout << "\tC::C()\n";
+ }
+
+ C(C&&) noexcept
+ {
+ std::cout << "\tC::C(C&&)\n";
+ }
+
+ C(const C&)
+ {
+ std::cout << "\tC::C(const C&)\n";
+ }
+
+ C& operator=(C&&) noexcept
+ {
+ std::cout << "\tC::operator=(C&&)\n";
+ return *this;
+ }
+
+ C& operator=(const C&)
+ {
+ std::cout << "\tC::operator=(const C&)\n";
+ return *this;
+ }
+
+ ~C()
+ {
+ std::cout << "\tC::~C()\n";
+ }
+ };
+
+ C make_rvo()
+ {
+ return C{};
+ }
+
+ C make_nrvo()
+ {
+ C c;
+ return c;
+ }
+}
+
+int main()
+{
+ {
+ std::cout << "C c\n";
+ C c;
+ }
+ {
+ std::cout << "C c(make_rvo())\n";
+ C c(make_rvo());
+ }
+ {
+ std::cout << "C c{make_rvo()}\n";
+ C c{make_rvo()};
+ }
+ {
+ std::cout << "C c = make_rvo()\n";
+ C c = make_rvo();
+ }
+ return 0;
+}