test6.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //-----------------------------------------------------------------------------
  2. // boost-libs variant/test/test6.cpp header file
  3. // See http://www.boost.org for updates, documentation, and revision history.
  4. //-----------------------------------------------------------------------------
  5. //
  6. // Copyright (c) 2003
  7. // Eric Friedman, Itay Maman
  8. //
  9. // Distributed under the Boost Software License, Version 1.0. (See
  10. // accompanying file LICENSE_1_0.txt or copy at
  11. // http://www.boost.org/LICENSE_1_0.txt)
  12. #include "boost/core/lightweight_test.hpp"
  13. #include "boost/variant.hpp"
  14. #include <iostream>
  15. #include "jobs.h"
  16. //Just Another Class
  17. struct jac
  18. {
  19. jac() { }
  20. jac(int ) { }
  21. jac(const char* ) { }
  22. };
  23. std::ostream& operator<<(std::ostream& out, const jac& )
  24. {
  25. out << "jac ";
  26. return out;
  27. }
  28. void run()
  29. {
  30. using boost::variant;
  31. variant<jac, int, double*, const double*> v1;
  32. variant<int, char, double*, const double*, char*> v2;
  33. v1 = v2;
  34. verify(v1, spec<int>());
  35. verify(v2, spec<int>());
  36. verify_not(v1, spec<jac>());
  37. verify_not(v1, spec<double*>());
  38. verify_not(v1, spec<const double*>());
  39. verify_not(v2, spec<char>());
  40. verify_not(v2, spec<double*>());
  41. verify_not(v2, spec<const double*>());
  42. verify_not(v2, spec<char*>());
  43. variant<jac, const double*> v3;
  44. variant<int, unsigned char, double*> v4;
  45. v3 = v4;
  46. verify(v3, spec<jac>());
  47. verify(v4, spec<int>());
  48. verify_not(v4, spec<unsigned char>());
  49. }
  50. int main()
  51. {
  52. run();
  53. return boost::report_errors();
  54. }