1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <iostream>
#include <vector>
void foo( std::vector<int>& seq, const char* expr_string )
{ std::cout << "foo - " << expr_string << " passed by lvalue reference\n" ; }
void foo( const std::vector<int>& seq, const char* expr_string )
{ std::cout << "foo - " << expr_string << " passed by lvalue reference to const\n" ; }
void foo( std::vector<int>&& seq, const char* expr_string )
{ std::cout << "foo - " << expr_string << " passed by rvalue reference\n" ; }
void bar( std::vector<int>& seq, const char* expr_string )
{ std::cout << "bar - " << expr_string << " passed by lvalue reference\n" ; }
void bar( const std::vector<int>& seq, const char* expr_string )
{ std::cout << "bar - " << expr_string << " passed by lvalue reference to const\n" ; }
void baz( const std::vector<int>& seq, const char* expr_string )
{ std::cout << "baz - " << expr_string << " passed by lvalue reference to const\n" ; }
std::vector<int> rvalue_expr() { return { 0, 1, 2, 3, 4, 5 } ; }
#define FOO(a) foo( (a), #a )
#define BAR(a) bar( (a), #a )
#define BAZ(a) baz( (a), #a )
int main ()
{
std::vector<int> lvalue_expr = { 6, 7, 8, 9 } ;
const std::vector<int> const_lvalue_expr = rvalue_expr() ;
FOO( lvalue_expr ) ;
FOO( const_lvalue_expr ) ;
FOO( rvalue_expr() ) ;
std::cout << "--------------\n" ;
BAR( lvalue_expr ) ;
BAR( const_lvalue_expr ) ;
BAR( rvalue_expr() ) ;
std::cout << "--------------\n" ;
BAZ( lvalue_expr ) ;
BAZ( const_lvalue_expr ) ;
BAZ( rvalue_expr() ) ;
}
|