implicit_cast.cpp 931 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright David Abrahams 2003.
  2. // Distributed under the Boost Software License, Version 1.0. (See
  3. // accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/implicit_cast.hpp>
  6. #include <boost/detail/lightweight_test.hpp>
  7. #include <boost/type.hpp>
  8. using boost::implicit_cast;
  9. using boost::type;
  10. template <class T>
  11. type<T> check_return(T) { return type<T>(); }
  12. struct foo
  13. {
  14. foo(char const*) {}
  15. operator long() const { return 0; }
  16. };
  17. typedef type<long> long_type;
  18. typedef type<foo> foo_type;
  19. int main()
  20. {
  21. type<long> x = check_return(boost::implicit_cast<long>(1));
  22. BOOST_TEST(boost::implicit_cast<long>(1) == 1L);
  23. type<foo> f = check_return(boost::implicit_cast<foo>("hello"));
  24. type<long> z = check_return(boost::implicit_cast<long>(foo("hello")));
  25. // warning suppression:
  26. (void)x;
  27. (void)f;
  28. (void)z;
  29. return boost::report_errors();
  30. }