103 lines
1.6 KiB
C++
103 lines
1.6 KiB
C++
/*
|
|
VIM: let b:lcppflags="-std=c++14 -O2 -pthread -I."
|
|
VIM: let b:wcppflags="/O2 /EHsc /DWIN32"
|
|
VIM-: let b:cppflags=g:Iboost.g:Itbb
|
|
VIM-: let b:ldflags=g:Lboost.g:Ltbb
|
|
VIM-: let b:ldlibpath=g:Bboost.g:Btbb
|
|
VIM-: let b:argv=""
|
|
*/
|
|
#include <iostream>
|
|
#include <exception>
|
|
|
|
class A
|
|
{
|
|
public:
|
|
int i;
|
|
|
|
A() {
|
|
std::cout << "default ctr" << std::endl;
|
|
}
|
|
|
|
A(const A&) {
|
|
std::cout << "copy ctr" << std::endl;
|
|
}
|
|
|
|
A(A&&) {
|
|
std::cout << "move ctr" << std::endl;
|
|
}
|
|
|
|
void operator = (const A&) {
|
|
std::cout << "copy" << std::endl;
|
|
}
|
|
|
|
void operator = (A&&) {
|
|
std::cout << "move" << std::endl;
|
|
}
|
|
};
|
|
|
|
void test3( A a ){
|
|
std::cout << "by value" << std::endl;
|
|
}
|
|
void test3( A&& a ){
|
|
std::cout << "rvalue" << std::endl;
|
|
}
|
|
void test3( const A& a ){
|
|
std::cout << "const lvalue&" << std::endl;
|
|
}
|
|
void test3( A& a ){
|
|
std::cout << "lvalue &" << std::endl;
|
|
}
|
|
|
|
|
|
template <typename T>
|
|
void test2( T&& t ){
|
|
test3(std::forward<T>(t));
|
|
}
|
|
|
|
template <typename T>
|
|
void test( T t ){
|
|
//test2(std::forward<T>(t));
|
|
test3(t);
|
|
}
|
|
|
|
A rvalue()
|
|
{
|
|
return A();
|
|
}
|
|
|
|
A& lvalue()
|
|
{
|
|
static A a;
|
|
return a;
|
|
}
|
|
|
|
const A& clvalue()
|
|
{
|
|
static A a;
|
|
return a;
|
|
}
|
|
|
|
|
|
int main ( void )
|
|
{try{
|
|
|
|
test(rvalue());
|
|
test(lvalue());
|
|
test(clvalue());
|
|
|
|
return 0;
|
|
}
|
|
catch ( const std::exception& e )
|
|
{
|
|
std::cerr << std::endl
|
|
<< "std::exception(\"" << e.what() << "\")." << std::endl;
|
|
return 2;
|
|
}
|
|
catch ( ... )
|
|
{
|
|
std::cerr << std::endl
|
|
<< "unknown exception." << std::endl;
|
|
return 1;
|
|
}}
|
|
|