rvalue_const.cpp 918 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // (C) Copyright Eric Niebler 2005.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. /*
  6. Revision history:
  7. 25 August 2005 : Initial version.
  8. */
  9. #include <vector>
  10. #include <boost/test/minimal.hpp>
  11. #include <boost/foreach.hpp>
  12. #ifdef BOOST_FOREACH_NO_CONST_RVALUE_DETECTION
  13. // ignore error during Microsoft Code Analysis
  14. #if !defined(_PREFAST_)
  15. # error Expected failure : const rvalues disallowed
  16. #endif
  17. #else
  18. std::vector<int> const get_vector()
  19. {
  20. return std::vector<int>(4, 4);
  21. }
  22. ///////////////////////////////////////////////////////////////////////////////
  23. // test_main
  24. //
  25. int test_main( int, char*[] )
  26. {
  27. int counter = 0;
  28. BOOST_FOREACH(int i, get_vector())
  29. {
  30. counter += i;
  31. }
  32. BOOST_CHECK(16 == counter);
  33. return 0;
  34. }
  35. #endif