explicit_operator_bool.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright Andrey Semashev 2007 - 2013.
  3. * Distributed under the Boost Software License, Version 1.0.
  4. * (See accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /*!
  8. * \file explicit_operator_bool.cpp
  9. * \author Andrey Semashev
  10. * \date 17.07.2010
  11. *
  12. * \brief This test checks that explicit operator bool can be used in
  13. * the valid contexts.
  14. */
  15. #define BOOST_TEST_MODULE explicit_operator_bool
  16. #include <boost/utility/explicit_operator_bool.hpp>
  17. namespace {
  18. // A test object that has the operator of explicit conversion to bool
  19. struct checkable1
  20. {
  21. BOOST_EXPLICIT_OPERATOR_BOOL()
  22. bool operator! () const
  23. {
  24. return false;
  25. }
  26. };
  27. struct checkable2
  28. {
  29. BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL()
  30. BOOST_CONSTEXPR bool operator! () const
  31. {
  32. return false;
  33. }
  34. };
  35. } // namespace
  36. int main(int, char*[])
  37. {
  38. checkable1 val1;
  39. if (val1)
  40. {
  41. checkable2 val2;
  42. if (val2)
  43. return 0;
  44. }
  45. return 1;
  46. }