Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "StdAfx.h"
- #include <iostream>
- #include <tchar.h>
- #include <type_traits>
- #include <vector>
- namespace
- {
- // put your realization here
- }
- namespace meta
- {
- template< class T >
- struct identity
- {
- typedef T
- type;
- };
- namespace impl
- {
- template< class T >
- struct investigate_type__impl
- : identity< typename identity< T >::type >
- {
- };
- } // namespace impl
- template< class T >
- struct investigate_type
- : identity< T >,
- impl::investigate_type__impl< T >
- {
- struct X
- {
- };
- typedef X type;
- };
- } // namespace meta
- std::vector< int > v;
- struct A
- {
- A() {}
- A( const A & )
- {
- v.push_back( 0 );
- std::cout << "copy" << std::endl;
- }
- A( A && )
- {
- v.push_back( 1 );
- std::cout << "move" << std::endl;
- }
- A &operator =( const A & )
- {
- v.push_back( 0 );
- std::cout << "copy" << std::endl;
- return *this;
- }
- A &operator =( A && )
- {
- v.push_back( 1 );
- std::cout << "move" << std::endl;
- return *this;
- }
- };
- template< class U >
- class Container
- {
- U member;
- public:
- U &Get(){ return member; }
- const U &Get() const{ return member; }
- public:
- template< class T > void dummy( const Container< T > & ); // copy
- template< class T > void dummy( Container< T > && ); // move
- public:
- // Ожидается, что T - это нечто совместимое с Container
- template< class T >
- void Fwd( T &&rr )
- {
- member = move_if_rr< T >( rr.Get() );
- // dummy( std::forward< T >( rr ) )
- }
- };
- int _tmain( int argc, _TCHAR* argv[] )
- {
- {
- struct A {};
- struct B {};
- //
- // < Result Type > = move_if_rr< In Fwd Type >( In Arg Type );
- //
- // In Fwd Type In Arg Type Result Type
- // /***************/ /******************/ /****************/
- static_assert( std::is_same< decltype( move_if_rr</**/A /**/>(/**/(const B &&)/**/(*(B *)nullptr) ) ),/**/const B &&/**/>::type::value, "Test failed!" );
- static_assert( std::is_same< decltype( move_if_rr</**/A /**/>(/**/(const B &) /**/(*(B *)nullptr) ) ),/**/const B &&/**/>::type::value, "Test failed!" );
- static_assert( std::is_same< decltype( move_if_rr</**/A /**/>(/**/(B &&) /**/(*(B *)nullptr) ) ),/**/B && /**/>::type::value, "Test failed!" );
- static_assert( std::is_same< decltype( move_if_rr</**/A /**/>(/**/(B &) /**/(*(B *)nullptr) ) ),/**/B && /**/>::type::value, "Test failed!" );
- // /**/ /**/ /**/ /**/ /**/ /**/
- static_assert( std::is_same< decltype( move_if_rr</**/A & /**/>(/**/(const B &&)/**/(*(B *)nullptr) ) ),/**/const B & /**/>::type::value, "Test failed!" );
- static_assert( std::is_same< decltype( move_if_rr</**/A & /**/>(/**/(const B &) /**/(*(B *)nullptr) ) ),/**/const B & /**/>::type::value, "Test failed!" );
- static_assert( std::is_same< decltype( move_if_rr</**/A & /**/>(/**/(B &&) /**/(*(B *)nullptr) ) ),/**/B & /**/>::type::value, "Test failed!" );
- static_assert( std::is_same< decltype( move_if_rr</**/A & /**/>(/**/(B &) /**/(*(B *)nullptr) ) ),/**/B & /**/>::type::value, "Test failed!" );
- // /**/ /**/ /**/ /**/ /**/ /**/
- static_assert( std::is_same< decltype( move_if_rr</**/const A &/**/>(/**/(const B &&)/**/(*(B *)nullptr) ) ),/**/const B & /**/>::type::value, "Test failed!" );
- static_assert( std::is_same< decltype( move_if_rr</**/const A &/**/>(/**/(const B &) /**/(*(B *)nullptr) ) ),/**/const B & /**/>::type::value, "Test failed!" );
- static_assert( std::is_same< decltype( move_if_rr</**/const A &/**/>(/**/(B &&) /**/(*(B *)nullptr) ) ),/**/B & /**/>::type::value, "Test failed!" );
- static_assert( std::is_same< decltype( move_if_rr</**/const A &/**/>(/**/(B &) /**/(*(B *)nullptr) ) ),/**/B & /**/>::type::value, "Test failed!" );
- // /**/ /**/ /**/ /**/ /**/ /**/
- static_assert( std::is_same< decltype( move_if_rr</**/const A /**/>(/**/(const B &&)/**/(*(B *)nullptr) ) ),/**/const B & /**/>::type::value, "Test failed!" );
- static_assert( std::is_same< decltype( move_if_rr</**/const A /**/>(/**/(const B &) /**/(*(B *)nullptr) ) ),/**/const B & /**/>::type::value, "Test failed!" );
- static_assert( std::is_same< decltype( move_if_rr</**/const A /**/>(/**/(B &&) /**/(*(B *)nullptr) ) ),/**/B & /**/>::type::value, "Test failed!" );
- static_assert( std::is_same< decltype( move_if_rr</**/const A /**/>(/**/(B &) /**/(*(B *)nullptr) ) ),/**/B & /**/>::type::value, "Test failed!" );
- // /***************/ /******************/ /****************/
- }
- Container< A > a;
- Container< A > x;
- const Container< A > cx;
- a.Fwd( (const Container< A > &)cx );
- a.Fwd( x );
- a.Fwd( cx );
- a.Fwd( std::move( x ) );
- a.Fwd( std::move( cx ) );
- a.Fwd( Container< A >() );
- std::cout << std::endl;
- if( v.size() == 6 &&
- v[0] == 0 &&
- v[1] == 0 &&
- v[2] == 0 &&
- v[3] == 1 &&
- v[4] == 0 &&
- v[5] == 1 )
- {
- std::cout << "Passed." << std::endl;
- }
- else
- {
- std::cout << "Failed." << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement