bug474.cpp 734 B

1234567891011121314151617181920212223242526272829303132
  1. // Range v3 library
  2. //
  3. // Use, modification and distribution is subject to the
  4. // Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // Project home: https://github.com/ericniebler/range-v3
  9. #include <vector>
  10. #include <range/v3/view/any_view.hpp>
  11. #include <range/v3/algorithm/for_each.hpp>
  12. struct Foo {
  13. Foo() = default;
  14. Foo(Foo const&) = default;
  15. virtual ~Foo() = default;
  16. virtual void foo() = 0;
  17. };
  18. struct Bar : public Foo {
  19. virtual void foo() override {}
  20. };
  21. int main()
  22. {
  23. std::vector<Bar> bars { Bar() };
  24. ranges::any_view<Foo &> foos = bars;
  25. ranges::for_each(foos, [] (Foo & foo) {
  26. foo.foo();
  27. });
  28. }