ref_unwrapped_example.cpp 1023 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Boost.Range library
  2. //
  3. // Copyright Robin Eckert 2015. Use, modification and distribution is
  4. // subject to the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. //
  9. // For more information, see http://www.boost.org/libs/range/
  10. //
  11. //[ref_unwrapped_example
  12. #include <boost/range/adaptor/ref_unwrapped.hpp>
  13. #include <iostream>
  14. #include <vector>
  15. struct example
  16. {
  17. int value;
  18. };
  19. int main(int argc, const char* argv[])
  20. {
  21. //<-
  22. #if !defined(BOOST_NO_CXX11_DECLTYPE) \
  23. && !defined(BOOST_NO_CXX11_RANGE_BASED_FOR) \
  24. && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) \
  25. && !defined(BOOST_NO_CXX11_AUTO_DECLARATIONS)
  26. //->
  27. using boost::adaptors::ref_unwrapped;
  28. example one{1};
  29. example two{2};
  30. example three{3};
  31. std::vector<std::reference_wrapper<example> > input{one, two, three};
  32. for (auto&& entry : input | ref_unwrapped)
  33. {
  34. std::cout << entry.value;
  35. }
  36. return 0;
  37. //<-
  38. #endif
  39. //->
  40. }
  41. //]