|
10 | 10 |
|
11 | 11 | #include <detail/accessor_impl.hpp> // for AccessorImplHost
|
12 | 12 | #include <detail/cg.hpp> // for CGExecKernel, CGHostTask, ArgDesc...
|
13 |
| -#include <detail/host_task.hpp> // for HostTask |
14 |
| -#include <sycl/detail/cg_types.hpp> // for CGType |
| 13 | +#include <detail/helpers.hpp> |
| 14 | +#include <detail/host_task.hpp> // for HostTask |
| 15 | +#include <sycl/detail/cg_types.hpp> // for CGType |
15 | 16 | #include <sycl/detail/kernel_desc.hpp> // for kernel_param_kind_t
|
16 | 17 |
|
17 | 18 | #include <cstring>
|
@@ -761,82 +762,43 @@ class node_impl : public std::enable_shared_from_this<node_impl> {
|
761 | 762 | }
|
762 | 763 | };
|
763 | 764 |
|
764 |
| -// Non-owning! |
765 |
| -class nodes_range { |
766 |
| - template <typename... Containers> |
767 |
| - using storage_iter_impl = |
768 |
| - std::variant<typename Containers::const_iterator...>; |
769 |
| - |
770 |
| - using storage_iter = storage_iter_impl< |
771 |
| - std::vector<std::shared_ptr<node_impl>>, std::vector<node_impl *>, |
772 |
| - // Next one is temporary. It looks like `weak_ptr`s aren't |
773 |
| - // used for the actual lifetime management and the objects are |
774 |
| - // always guaranteed to be alive. Once the code is cleaned |
775 |
| - // from `weak_ptr`s this alternative should be removed too. |
776 |
| - std::vector<std::weak_ptr<node_impl>>, |
777 |
| - // |
778 |
| - std::set<std::shared_ptr<node_impl>>, std::set<node_impl *>, |
779 |
| - // |
780 |
| - std::list<node_impl *>>; |
781 |
| - |
782 |
| - storage_iter Begin; |
783 |
| - storage_iter End; |
784 |
| - const size_t Size; |
785 |
| - |
786 |
| -public: |
787 |
| - nodes_range(const nodes_range &Other) = default; |
788 |
| - |
789 |
| - template < |
790 |
| - typename ContainerTy, |
791 |
| - typename = std::enable_if_t<!std::is_same_v<nodes_range, ContainerTy>>> |
792 |
| - nodes_range(ContainerTy &Container) |
793 |
| - : Begin{Container.begin()}, End{Container.end()}, Size{Container.size()} { |
| 765 | +struct nodes_deref_impl { |
| 766 | + template <typename T> static node_impl &dereference(T &Elem) { |
| 767 | + if constexpr (std::is_same_v<std::decay_t<decltype(Elem)>, |
| 768 | + std::weak_ptr<node_impl>>) { |
| 769 | + // This assumes that weak_ptr doesn't actually manage lifetime and |
| 770 | + // the object is guaranteed to be alive (which seems to be the |
| 771 | + // assumption across all graph code). |
| 772 | + return *Elem.lock(); |
| 773 | + } else { |
| 774 | + return *Elem; |
| 775 | + } |
794 | 776 | }
|
| 777 | +}; |
795 | 778 |
|
796 |
| - class iterator { |
797 |
| - storage_iter It; |
798 |
| - |
799 |
| - iterator(storage_iter It) : It(It) {} |
800 |
| - friend class nodes_range; |
801 |
| - |
802 |
| - public: |
803 |
| - iterator &operator++() { |
804 |
| - It = std::visit( |
805 |
| - [](auto &&It) { |
806 |
| - ++It; |
807 |
| - return storage_iter{It}; |
808 |
| - }, |
809 |
| - It); |
810 |
| - return *this; |
811 |
| - } |
812 |
| - bool operator!=(const iterator &Other) const { return It != Other.It; } |
813 |
| - |
814 |
| - node_impl &operator*() { |
815 |
| - return std::visit( |
816 |
| - [](auto &&It) -> node_impl & { |
817 |
| - auto &Elem = *It; |
818 |
| - if constexpr (std::is_same_v<std::decay_t<decltype(Elem)>, |
819 |
| - std::weak_ptr<node_impl>>) { |
820 |
| - // This assumes that weak_ptr doesn't actually manage lifetime and |
821 |
| - // the object is guaranteed to be alive (which seems to be the |
822 |
| - // assumption across all graph code). |
823 |
| - return *Elem.lock(); |
824 |
| - } else { |
825 |
| - return *Elem; |
826 |
| - } |
827 |
| - }, |
828 |
| - It); |
829 |
| - } |
830 |
| - }; |
| 779 | +template <typename... ContainerTy> |
| 780 | +using nodes_iterator_impl = |
| 781 | + variadic_iterator<nodes_deref_impl, |
| 782 | + typename ContainerTy::const_iterator...>; |
| 783 | + |
| 784 | +using nodes_iterator = nodes_iterator_impl< |
| 785 | + std::vector<std::shared_ptr<node_impl>>, std::vector<node_impl *>, |
| 786 | + // Next one is temporary. It looks like `weak_ptr`s aren't |
| 787 | + // used for the actual lifetime management and the objects are |
| 788 | + // always guaranteed to be alive. Once the code is cleaned |
| 789 | + // from `weak_ptr`s this alternative should be removed too. |
| 790 | + std::vector<std::weak_ptr<node_impl>>, |
| 791 | + // |
| 792 | + std::set<std::shared_ptr<node_impl>>, std::set<node_impl *>, |
| 793 | + // |
| 794 | + std::list<node_impl *>>; |
| 795 | + |
| 796 | +class nodes_range : public iterator_range<nodes_iterator> { |
| 797 | +private: |
| 798 | + using Base = iterator_range<nodes_iterator>; |
831 | 799 |
|
832 |
| - iterator begin() const { |
833 |
| - return {std::visit([](auto &&It) { return storage_iter{It}; }, Begin)}; |
834 |
| - } |
835 |
| - iterator end() const { |
836 |
| - return {std::visit([](auto &&It) { return storage_iter{It}; }, End)}; |
837 |
| - } |
838 |
| - size_t size() const { return Size; } |
839 |
| - bool empty() const { return Size == 0; } |
| 800 | +public: |
| 801 | + using Base::Base; |
840 | 802 | };
|
841 | 803 |
|
842 | 804 | inline nodes_range node_impl::successors() const { return MSuccessors; }
|
|
0 commit comments