View.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. /*
  3. * Copyright (c) Contributors to the Open 3D Engine Project.
  4. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. *
  6. * SPDX-License-Identifier: Apache-2.0 OR MIT
  7. *
  8. */
  9. namespace AZ
  10. {
  11. namespace SceneAPI
  12. {
  13. namespace Containers
  14. {
  15. namespace Views
  16. {
  17. // View combines begin and end iterators together in a single object.
  18. // This reduces the number of functions that are needed to pass
  19. // iterators from functions and avoids problems with mismatched
  20. // iterators. It also makes it easier to use in ranged-based
  21. // for-loops.
  22. // Note that const correctness is enforced by the type of
  23. // iterator passed, so all versions of begin and end return
  24. // the same value.
  25. template<typename Iterator>
  26. class View
  27. {
  28. public:
  29. using iterator = Iterator;
  30. using const_iterator = Iterator;
  31. View(Iterator begin, Iterator end);
  32. Iterator begin();
  33. Iterator end();
  34. Iterator begin() const;
  35. Iterator end() const;
  36. Iterator cbegin() const;
  37. Iterator cend() const;
  38. [[nodiscard]] bool empty() const;
  39. private:
  40. Iterator m_begin;
  41. Iterator m_end;
  42. };
  43. template<typename Iterator>
  44. View<Iterator> MakeView(Iterator begin, Iterator end)
  45. {
  46. return View<Iterator>(begin, end);
  47. }
  48. } // Views
  49. } // Containers
  50. } // SceneAPI
  51. } // AZ
  52. #include <SceneAPI/SceneCore/Containers/Views/View.inl>