is_instance_of_test.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include <boost/test/minimal.hpp> // see "Header Implementation Option"
  13. #include "boost/lambda/detail/is_instance_of.hpp"
  14. #include <iostream>
  15. template <class T1> struct A1 {};
  16. template <class T1, class T2> struct A2 {};
  17. template <class T1, class T2, class T3> struct A3 {};
  18. template <class T1, class T2, class T3, class T4> struct A4 {};
  19. class B1 : public A1<int> {};
  20. class B2 : public A2<int,int> {};
  21. class B3 : public A3<int,int,int> {};
  22. class B4 : public A4<int,int,int,int> {};
  23. // classes that are convertible to classes that derive from A instances
  24. // This is not enough to make the test succeed
  25. class C1 { public: operator A1<int>() { return A1<int>(); } };
  26. class C2 { public: operator B2() { return B2(); } };
  27. class C3 { public: operator B3() { return B3(); } };
  28. class C4 { public: operator B4() { return B4(); } };
  29. // test that the result is really a constant
  30. // (in an alternative implementation, gcc 3.0.2. claimed that it was
  31. // a non-constant)
  32. template <bool b> class X {};
  33. // this should compile
  34. X<boost::lambda::is_instance_of_2<int, A2>::value> x;
  35. int test_main(int, char *[]) {
  36. using boost::lambda::is_instance_of_1;
  37. using boost::lambda::is_instance_of_2;
  38. using boost::lambda::is_instance_of_3;
  39. using boost::lambda::is_instance_of_4;
  40. BOOST_CHECK((is_instance_of_1<B1, A1>::value == true));
  41. BOOST_CHECK((is_instance_of_1<A1<float>, A1>::value == true));
  42. BOOST_CHECK((is_instance_of_1<int, A1>::value == false));
  43. BOOST_CHECK((is_instance_of_1<C1, A1>::value == false));
  44. BOOST_CHECK((is_instance_of_2<B2, A2>::value == true));
  45. BOOST_CHECK((is_instance_of_2<A2<int, float>, A2>::value == true));
  46. BOOST_CHECK((is_instance_of_2<int, A2>::value == false));
  47. BOOST_CHECK((is_instance_of_2<C2, A2>::value == false));
  48. BOOST_CHECK((is_instance_of_3<B3, A3>::value == true));
  49. BOOST_CHECK((is_instance_of_3<A3<int, float, char>, A3>::value == true));
  50. BOOST_CHECK((is_instance_of_3<int, A3>::value == false));
  51. BOOST_CHECK((is_instance_of_3<C3, A3>::value == false));
  52. BOOST_CHECK((is_instance_of_4<B4, A4>::value == true));
  53. BOOST_CHECK((is_instance_of_4<A4<int, float, char, double>, A4>::value == true));
  54. BOOST_CHECK((is_instance_of_4<int, A4>::value == false));
  55. BOOST_CHECK((is_instance_of_4<C4, A4>::value == false));
  56. return 0;
  57. }