OSDN Git Service

call_traits 関連で微更新 + cast のテストコードを追加
[gintenlib/gintenlib.git] / tests / enable_if.cc
1 // ヘッダのインクルード
2 #include <gintenlib/preprocessor/enable_if.hpp>
3
4 // boost の単体テストフレームワーク
5 #include <boost/test/minimal.hpp>
6
7 // テストに使うクラス
8 struct base {};
9 struct derived : base {};
10
11 // テストに使うメタ関数
12 #include <boost/type_traits/is_base_of.hpp>
13
14 // GINTENLIB_ENABLE_IF のチェック
15 // これさえ通れば、この内部で使われている
16 // <gintenlib/enable_if.hpp>
17 // <gintenlib/d_enable_if.hpp>
18 // <gintenlib/preprocessor/dequote.hpp>
19 // これらのチェックも自動的に通ったことになる
20 template<typename T>
21 bool hoge( const T&,  GINTENLIB_ENABLE_IF(( boost::is_base_of<base, T> )) )
22 {
23   return true;
24 }
25 template<typename T>
26 bool hoge( const T&, GINTENLIB_DISABLE_IF(( boost::is_base_of<base, T> )) )
27 {
28   return false;
29 }
30
31
32 // 単体テスト本体
33 int test_main( int argc, char* argv[] )
34 {
35   derived d;
36   int i;
37   
38   BOOST_CHECK(  hoge(d) );
39   BOOST_CHECK( !hoge(i) );
40   
41   return 0;
42 }