initial check in
This commit is contained in:
68
test_rvalue_ref.cpp
Normal file
68
test_rvalue_ref.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
class copy_tracker
|
||||
{
|
||||
int v;
|
||||
public:
|
||||
copy_tracker()
|
||||
: v(0)
|
||||
{
|
||||
std::cout << "copy_tracker::copy_tracker()" << std::endl;
|
||||
}
|
||||
|
||||
copy_tracker( const copy_tracker& c )
|
||||
: v( c.v )
|
||||
{
|
||||
std::cout << "copy_tracker::copy_tracker( copy_tracker& c )" << std::endl;
|
||||
}
|
||||
|
||||
void use_object() const
|
||||
{
|
||||
std::cout << v << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
copy_tracker create_rvalue()
|
||||
{
|
||||
return copy_tracker();
|
||||
}
|
||||
|
||||
const copy_tracker create_const_rvalue()
|
||||
{
|
||||
return copy_tracker();
|
||||
}
|
||||
|
||||
void f ( copy_tracker&& o )
|
||||
{
|
||||
o.use_object();
|
||||
}
|
||||
|
||||
void f_const ( const copy_tracker&& o )
|
||||
{
|
||||
o.use_object();
|
||||
}
|
||||
|
||||
void aaa( const std::string& s )
|
||||
{
|
||||
std::cout << s << std::endl;
|
||||
}
|
||||
|
||||
int main( void )
|
||||
{
|
||||
|
||||
f( create_rvalue() );
|
||||
|
||||
f_const( create_rvalue() );
|
||||
f_const( create_const_rvalue() );
|
||||
|
||||
copy_tracker lvalue;
|
||||
f( std::move(lvalue) );
|
||||
f_const( std::move(lvalue) );
|
||||
|
||||
aaa( "aaaa");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user