Skip to content

Commit

Permalink
Change template name to more-standard T.
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendanKKrueger committed Sep 13, 2024
1 parent ca5e117 commit 8e47f7b
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions ports-of-call/span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ namespace PortsOfCall {
// Heavily simplified relative to std::span, but provides a similar concept in a way
// that's portable to GPUs.

template <typename DataType>
template <typename T>
class span {
private:
DataType *ptr_{nullptr};
T *ptr_{nullptr};
std::size_t size_{0};

public:
Expand All @@ -33,7 +33,7 @@ class span {
// object provides access to indices 2 <= i < 8 of the array my_array, but the indices
// are shifted so that sub_range[i] is my_array[i+2].
template <typename SizeType>
PORTABLE_FUNCTION constexpr span(DataType *ptr, SizeType const &count)
PORTABLE_FUNCTION constexpr span(T *ptr, SizeType const &count)
: ptr_{ptr}, size_(count) {
assert(count >= 0);
}
Expand All @@ -42,34 +42,34 @@ class span {
PORTABLE_FUNCTION constexpr auto size() const { return size_; }

// Iterator (really a pointer) to the beginning of the range, providing mutable access.
PORTABLE_FUNCTION constexpr DataType *begin() { return ptr_; }
PORTABLE_FUNCTION constexpr T *begin() { return ptr_; }

// Iterator (really a pointer) to the beginning of the range, providing constant access.
PORTABLE_FUNCTION constexpr DataType const *begin() const { return ptr_; }
PORTABLE_FUNCTION constexpr T const *begin() const { return ptr_; }

// Iterator (really a pointer) to the beginning of the range, providing constant access.
PORTABLE_FUNCTION constexpr DataType const *cbegin() const { return ptr_; }
PORTABLE_FUNCTION constexpr T const *cbegin() const { return ptr_; }

// Iterator (really a pointer) to the end of the range, providing mutable access.
PORTABLE_FUNCTION constexpr DataType *end() { return ptr_ + size_; }
PORTABLE_FUNCTION constexpr T *end() { return ptr_ + size_; }

// Iterator (really a pointer) to the beginning of the range, providing constant access.
PORTABLE_FUNCTION constexpr DataType const *end() const { return ptr_ + size_; }
PORTABLE_FUNCTION constexpr T const *end() const { return ptr_ + size_; }

// Iterator (really a pointer) to the beginning of the range, providing constant access.
PORTABLE_FUNCTION constexpr DataType const *cend() const { return ptr_ + size_; }
PORTABLE_FUNCTION constexpr T const *cend() const { return ptr_ + size_; }

// Index operator to obtain mutable access to an element of the range.
template <typename Index>
PORTABLE_FUNCTION constexpr DataType &operator[](Index const &index) {
PORTABLE_FUNCTION constexpr T &operator[](Index const &index) {
assert(index >= 0);
assert(static_cast<std::size_t>(index) < size_);
return *(ptr_ + index);
}

// Index operator to obtain constant access to an element of the range.
template <typename Index>
PORTABLE_FUNCTION constexpr DataType const &operator[](Index const &index) const {
PORTABLE_FUNCTION constexpr T const &operator[](Index const &index) const {
assert(index >= static_cast<Index>(0));
assert(index < static_cast<Index>(size_));
return *(ptr_ + index);
Expand All @@ -78,10 +78,10 @@ class span {

// ================================================================================================

template <typename DataType, typename SizeType>
PORTABLE_FUNCTION constexpr auto make_span(DataType *const pointer,
template <typename T, typename SizeType>
PORTABLE_FUNCTION constexpr auto make_span(T *const pointer,
SizeType const count) {
return span<DataType>(pointer, count);
return span<T>(pointer, count);
}

// ================================================================================================
Expand Down

0 comments on commit 8e47f7b

Please sign in to comment.