Loading...
Searching...
No Matches
range.cuh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022, NVIDIA CORPORATION.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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
Abstract Data Type (ADT) for any containers representable with a start and end iterator.
Definition range.cuh:43
auto &CUSPATIAL_HOST_DEVICE operator[](IndexType i)
Access the ith element in the range.
Definition range.cuh:57
auto CUSPATIAL_HOST_DEVICE end()
Return the end iterator to the range.
Definition range.cuh:51
auto CUSPATIAL_HOST_DEVICE begin()
Return the start iterator to the range.
Definition range.cuh:49
auto CUSPATIAL_HOST_DEVICE size()
Return the size of the range.
Definition range.cuh:53