PageRenderTime 37ms CodeModel.GetById 24ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/phoenix/test/bll_compatibility/is_instance_of_test.cpp

http://hadesmem.googlecode.com/
C++ | 79 lines | 40 code | 22 blank | 17 comment | 16 complexity | 99b2b667eae94d12f69ba03d2d45b81c MD5 | raw file
 1// is_instance_of_test.cpp -- The Boost Lambda Library ------------------
 2//
 3// Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
 4// Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
 5//
 6// Distributed under the Boost Software License, Version 1.0. (See
 7// accompanying file LICENSE_1_0.txt or copy at
 8// http://www.boost.org/LICENSE_1_0.txt)
 9//
10// For more information, see www.boost.org
11
12// -----------------------------------------------------------------------
13
14
15#include <boost/test/minimal.hpp>    // see "Header Implementation Option"
16 
17
18#include "boost/lambda/detail/is_instance_of.hpp"
19
20#include <iostream>
21
22template <class T1> struct A1 {};
23template <class T1, class T2> struct A2 {};
24template <class T1, class T2, class T3> struct A3 {};
25template <class T1, class T2, class T3, class T4> struct A4 {};
26 
27class B1 : public A1<int> {};
28class B2 : public A2<int,int> {};
29class B3 : public A3<int,int,int> {};
30class B4 : public A4<int,int,int,int> {};
31
32// classes that are convertible to classes that derive from A instances 
33// This is not enough to make the test succeed
34
35class C1 { public: operator A1<int>() { return A1<int>(); } };
36class C2 { public: operator B2() { return B2(); } };
37class C3 { public: operator B3() { return B3(); } };
38class C4 { public: operator B4() { return B4(); } };
39 
40// test that the result is really a constant
41// (in an alternative implementation, gcc 3.0.2. claimed that it was 
42// a non-constant)
43template <bool b> class X {};
44// this should compile 
45X<boost::lambda::is_instance_of_2<int, A2>::value> x;
46
47
48int test_main(int, char *[]) {
49
50using boost::lambda::is_instance_of_1;
51using boost::lambda::is_instance_of_2;
52using boost::lambda::is_instance_of_3;
53using boost::lambda::is_instance_of_4;
54
55
56BOOST_CHECK((is_instance_of_1<B1, A1>::value == true));
57BOOST_CHECK((is_instance_of_1<A1<float>, A1>::value == true));
58BOOST_CHECK((is_instance_of_1<int, A1>::value == false));
59BOOST_CHECK((is_instance_of_1<C1, A1>::value == false));
60
61BOOST_CHECK((is_instance_of_2<B2, A2>::value == true));
62BOOST_CHECK((is_instance_of_2<A2<int, float>, A2>::value == true));
63BOOST_CHECK((is_instance_of_2<int, A2>::value == false));
64BOOST_CHECK((is_instance_of_2<C2, A2>::value == false));
65
66BOOST_CHECK((is_instance_of_3<B3, A3>::value == true));
67BOOST_CHECK((is_instance_of_3<A3<int, float, char>, A3>::value == true));
68BOOST_CHECK((is_instance_of_3<int, A3>::value == false));
69BOOST_CHECK((is_instance_of_3<C3, A3>::value == false));
70
71BOOST_CHECK((is_instance_of_4<B4, A4>::value == true));
72BOOST_CHECK((is_instance_of_4<A4<int, float, char, double>, A4>::value == true));
73BOOST_CHECK((is_instance_of_4<int, A4>::value == false));
74BOOST_CHECK((is_instance_of_4<C4, A4>::value == false));
75
76return 0;
77
78}
79