Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<functional>
- #include<boost/function.hpp>
- struct A
- {
- static int s;
- int i;
- A() : i(++s)
- { std::cout << "ctorA : " << i << std::endl; }
- A(A const &) : i(++s)
- { std::cout << "copyA : " << i << std::endl; }
- ~A()
- { std::cout << "dtorA : " << i << std::endl; }
- A(A&&) =delete;
- A& operator=(A const &) =delete;
- A& operator=(A&&) =delete;
- };
- int A::s = 0;
- //Case lambda/function
- /*struct L
- {
- A& a;
- L(A& a) : a(a)
- { std::cout << "ctorL " << std::endl; }
- L(L const & l) : a(l.a)
- { std::cout << "copyL " << std::endl; }
- ~L()
- { std::cout << "dtorL " << std::endl; }
- A operator()() const
- { return a; }
- L(L&&) =delete;
- L& operator=(L const &) =delete;
- L& operator=(L&&) =delete;
- };
- struct F
- {
- L l;
- F(L const & l) : l(l)
- { std::cout << "ctorF " << std::endl; }
- F(F const & f) : l(f.l)
- { std::cout << "copyF " << std::endl; }
- ~F()
- { std::cout << "dtorF " << std::endl; }
- A const & operator()() const
- { return l(); }
- F(F&&) =delete;
- F& operator=(F const &) =delete;
- F& operator=(F&&) =delete;
- };*/
- //Case 1
- /*struct B
- {
- A const & a;
- B() : a(A())
- { std::cout << "ctorB " << std::endl; }
- ~B()
- { std::cout << "dtorB " << std::endl; }
- B(B const &) =delete;
- B(B&&) =delete;
- B& operator=(B const &) =delete;
- B& operator=(B&&) =delete;
- };
- //Case 2
- void foo(A const &)
- { }*/
- //Case 3
- /*A const & foo()
- { return A(); }*/
- //Case 4
- /*struct B
- {
- A const & a;
- B(A const & a) : a(a)
- { std::cout << "ctorB " << std::endl; }
- ~B()
- { std::cout << "dtorB " << std::endl; }
- B(B const &) =delete;
- B(B&&) =delete;
- B& operator=(B const &) =delete;
- B& operator=(B&&) =delete;
- };*/
- //Case 5
- /*A const & foo(A const & a)
- { return a; }*/
- //Case 6
- /*A const & foo(A a)
- { return a; }*/
- int main()
- {
- //Case 1
- /* std::cout << "1/ ";
- B b;
- std::cout << "2/ ";*/
- //Warn
- //Case 2
- /* std::cout << "1/ ";
- foo(A());
- std::cout << "2/ ";*/
- //Case 3
- /* std::cout << "1/ ";
- A const & a = foo();
- std::cout << "2/ ";*/
- //Warn
- //Case 4
- /* std::cout << "1/ ";
- B* b = new B(A());
- std::cout << "2/ ";
- delete b;
- std::cout << "3/ ";*/
- //Case 5
- /* std::cout << "1/ ";
- A const & a = foo(A());
- std::cout << "2/ ";*/
- //Case 6
- /* std::cout << "1/ ";
- A a1;
- std::cout << "2/ ";
- A const & a2 = foo(a1);
- std::cout << "3/ ";*/
- //Warn
- //Case lambda/function
- /* std::cout << "1/ ";
- A a1;
- std::cout << "2/ ";
- L l(a1);
- std::cout << "3/ ";
- F f(l);
- std::cout << "4/ ";
- A const & a2 = f();
- std::cout << "5/ ";*/
- //Case True
- /* std::cout << "1/ ";
- A a1;
- std::cout << "2/ ";
- auto l = [&a1]{return a1;};
- std::cout << "3/ ";
- std::function<A const & ()> f(l);
- std::cout << "4/ ";
- A const & a2 = f();
- std::cout << "5/ ";*/
- //Case Boost
- /* std::cout << "1/ ";
- A a1;
- std::cout << "2/ ";
- auto l = [&a1]{return a1;};
- std::cout << "3/ ";
- boost::function<A const & ()> f(l);
- std::cout << "4/ ";
- A const & a2 = f();
- std::cout << "5/ ";*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement