void main() { }

Hello ,world !

常用链接

统计

最新评论

test Loki::Typelist

      昨晚,测试  Loki C++ 库 Typelist.h 的一些功能 -- 在BCB 6.0 环境下 。随便晒晒了:

//---------------------------------------------------------------------------
#include <vcl.h>
#include 
<iostream>
#include 
<string> 
#include 
<typeinfo>
#include 
<windows.h>

using namespace std;
#include 
"loki\Typelist.h"

int main(int argc,char* argv[])
{
    
using namespace Loki ;   

// ---- test TYPELIST_N -----------------
    cout << " ---- test TYPELIST_N -----" << "\n" ;
    typedef TYPELIST_4(signed 
charshort intintlong int)
            SignedIntegrals ;
    cout 
<< " typedef TYPELIST_4(signed char, short int, int, long int)"
         
<< " SignedIntegrals ;" << "\n" ;

// ---- test Length<>  -----------------
    cout << " ---- test Length<>  -----" << "\n" ;
    cout 
<< TL::Length<SignedIntegrals>::value << "\n" ;
    cout 
<< typeid(TL::TypeAt<SignedIntegrals ,1>::Result).name() << "\n" ; 
// ---- test IndexOf -----------------
    cout << TL::IndexOf<SignedIntegrals ,int>::value << "\n" ;
// ---- test Append<>  -----------------
    cout << " ---- test Append<>  ----" << "\n" ;
    typedef TL::Append
<SignedIntegrals ,string>::Result Result ;
    cout 
<< TL::Length<Result>::value << "\n" ; //
    cout << typeid(TL::TypeAt<Result ,4>::Result).name() << "\n" ;
    
// or : typedef TYPELIST_2(string ,String) SString ; //sString
    typedef TL::Append<Result ,TYPELIST_2(string ,String) >::Result Result ;
    cout 
<< TL::Length<Result>::value << "\n" ;
    
//for(int i=0 ;i<TL::Length<Result>::value ;i++)     //
        
//cout << typeid(TL::TypeAt<Result ,ConstI>::Result).name() << "\n" ;
    
//[C++ Error] E2396 Template argument must be a constant expression

// ---- test TypeAt<>  -----------------
    cout << " ---- test TypeAt<>  ----" << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,6>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,5>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,4>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,3>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,2>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,1>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,0>::Result).name() << "\n" ;
// ---- test Erase<>  -----------------
    cout << " ---- test Erase<>  ----" << "\n" ;
    cout 
<< TL::Length<TL::Erase<Result ,double>::Result>::value << "\n" ;// no double erase none
    cout << TL::Length<Result>::value << "\n" ;
    typedef TL::Erase
<Result ,string>::Result Result ; // erase string OK
    cout << TL::Length<Result>::value << "\n" ;
    typedef TL::Erase
<Result ,string>::Result Result ; // erase string OK
    cout << TL::Length<Result>::value << "\n" ;
    typedef TL::Erase
<Result ,string>::Result Result ;// no string erase none
    cout << TL::Length<Result>::value << "\n" ;
// ---- test Replace<>  -----------------
    cout << " ---- test Replace<>  ----" << "\n" ;
    cout 
<< TL::IndexOf<Result ,String>::value << "\n" ;// String exist -- 4     
    cout << TL::IndexOf<Result ,string>::value << "\n" ; // String doesn't exist -- -1
    typedef TL::Replace<Result ,String ,string>::Result Result ; // Replace String to string OK
    cout << TL::IndexOf<Result ,String>::value << "\n" ; // String doesn't exist -- -1
    cout << TL::IndexOf<Result ,string>::value << "\n" ; // string exist -- 4
// ---- test ReplaceAll<>  -----------------
    cout << " ---- test ReplaceAll<>  ----" << "\n" ;
    typedef TL::Append
<Result ,TYPELIST_2(string ,string>::Result Result ;
    cout 
<< typeid(TL::TypeAt<Result ,4>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,5>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,6>::Result).name() << "\n" ; 
    typedef TL::ReplaceAll
<Result ,string ,String >::Result Result ;   
    cout 
<< typeid(TL::TypeAt<Result ,4>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,5>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,6>::Result).name() << "\n" ;
// ---- test Reverse<>  -----------------
    cout << " ---- test Reverse<>  ----" << "\n" ;
    
using namespace Loki::TL ;
    cout 
<< Length<Result>::value << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,0>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,1>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,2>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,3>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,4>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,5>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,6>::Result).name() << "\n" ;
    typedef Reverse
<Result>::Result Result ;
    cout 
<< typeid(TL::TypeAt<Result ,0>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,1>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,2>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,3>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,4>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,5>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,6>::Result).name() << "\n" ;
// ---- test NoDuplicates<>  --------------------   
    cout << " " << "\n" ;

// ---- test MostDerived<>  ---------------------  
    cout << " " << "\n" ;

// ---- test DerivedToFront<>  ------------------  
    cout << " " << "\n" ;

// ---- test EraseALL<> -----------------
    cout << " ---- test EraseALL<> -----" << "\n" ;
    cout 
<< Length<Result>::value << endl ;
    typedef EraseAll
<Result ,String>::Result Result ;
    cout 
<< Length<Result>::value << endl ;
    cout 
<< typeid(TL::TypeAt<Result ,0>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,1>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,2>::Result).name() << "\n" ;
    cout 
<< typeid(TL::TypeAt<Result ,3>::Result).name() << "\n" ;  
    typedef Replace
<Result ,SignedIntegrals ,NullType>::Result Result ;// no replace 
    cout << Length<Result>::value << endl ;    
    typedef EraseAll
<Result ,SignedIntegrals>::Result Result ; // no erase
    cout << Length<Result>::value << endl ;

/*  ***********************************************************/
    cout 
<< "\n\n\n\n       Hello ,World !" <<endl ;
    system(
"pause");
    
return 0;
}



//---------------------------------------------------------------------------

继续好好学习Modern C++ Design -- C++ 设计新思维 。

posted on 2009-07-09 13:34 only 阅读(444) 评论(0)  编辑 收藏 引用 所属分类: 琐碎编程


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理