加载中...
搜索中...
无匹配项
range.cuh
前往此文件的文档。
1/*
2 * 版权所有 (c) 2022, NVIDIA CORPORATION.
3 *
4 * 根据 Apache 许可证版本 2.0 (以下简称“许可证”) 获得许可;
5 * 除非符合许可证的规定,否则您不得使用此文件。
6 * 您可以在以下位置获得许可证副本:
7 *
8 * https://apache.ac.cn/licenses/LICENSE-2.0
9 *
10 * 除非适用法律要求或书面同意,否则软件
11 * 根据许可证分发,是按“原样”分发的,
12 * 不附带任何形式的明示或暗示保证或条件。
13 * 有关管理权限和
14 * 限制的特定语言,请参阅许可证。
15 */
16
17#pragma once
18
19#include <cuspatial/cuda_utils.hpp>
20#include <cuspatial/traits.hpp>
21
22#include <thrust/detail/raw_reference_cast.h>
23#include <thrust/distance.h>
24
25namespace cuspatial {
26
42template <typename IteratorType>
43class range {
44 public
45 using value_type = iterator_value_type<IteratorType>;
46 range(IteratorType begin, IteratorType end) : _begin(begin), _end(end) {}
47
49 auto CUSPATIAL_HOST_DEVICE begin() { return _begin; }
51 auto CUSPATIAL_HOST_DEVICE end() { return _end; }
53 auto CUSPATIAL_HOST_DEVICE size() { return thrust::distance(_begin, _end); }
54
56 template <typename IndexType>
57 auto& CUSPATIAL_HOST_DEVICE operator[](IndexType i)
58 {
59 return thrust::raw_reference_cast(_begin[i]);
60 }
61
62 private
63 IteratorType _begin;
64 IteratorType _end;
65};
66
67} // namespace cuspatial
auto &CUSPATIAL_HOST_DEVICE operator[](IndexType i)
访问范围内的第 i 个元素。
auto CUSPATIAL_HOST_DEVICE end()
返回范围的结束迭代器。
auto CUSPATIAL_HOST_DEVICE begin()
返回范围的起始迭代器。
auto CUSPATIAL_HOST_DEVICE size()
返回范围的大小。