-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
104 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
#pragma once | ||
|
||
template <class T, size_t n> | ||
size_t arraySize(T const (&)[n]) { | ||
return n; | ||
} | ||
#pragma once | ||
|
||
/*! Return the size of an arbitrary array. | ||
* | ||
* \param - Array reference. | ||
* | ||
* \return Array size. | ||
*/ | ||
template <class T, size_t n> | ||
size_t arraySize(T const (&)[n]) { | ||
return n; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,92 @@ | ||
#pragma once | ||
|
||
template <class T> | ||
class Span { | ||
public: | ||
/*! Create a Span with `n` elements. | ||
* | ||
* \tparam n Number of elements. | ||
* | ||
* \param arr Array. | ||
*/ | ||
template <size_t n> | ||
Span(T (&arr)[n]); | ||
|
||
|
||
T& operator [](size_t const); | ||
T const& operator [](size_t const) const; | ||
|
||
|
||
T* begin(); | ||
T* end(); | ||
T const* begin() const; | ||
T const* end() const; | ||
|
||
|
||
/*! Get the underlying data. | ||
* | ||
* \return data. | ||
*/ | ||
T* data() const; | ||
|
||
/*! Get the number of elements. | ||
* | ||
* \return Span size. | ||
*/ | ||
size_t size() const; | ||
|
||
private: | ||
T* arr_ {}; | ||
size_t size_ {}; | ||
}; | ||
|
||
|
||
template <class T> | ||
template <size_t n> | ||
Span<T>::Span(T (&arr)[n]) : arr_ {arr}, size_ {n} {} | ||
|
||
|
||
template <class T> | ||
T& Span<T>::operator [](size_t const idx) { | ||
return arr_[idx]; | ||
} | ||
|
||
template <class T> | ||
T const& Span<T>::operator [](size_t const idx) const { | ||
return arr_[idx]; | ||
} | ||
|
||
|
||
template <class T> | ||
T* Span<T>::begin() { | ||
return arr_; | ||
} | ||
|
||
template <class T> | ||
T* Span<T>::end() { | ||
return arr_ + size_; | ||
} | ||
|
||
template <class T> | ||
T const* Span<T>::begin() const { | ||
return arr_; | ||
} | ||
|
||
template <class T> | ||
T const* Span<T>::end() const { | ||
return arr_ + size_; | ||
} | ||
|
||
|
||
template <class T> | ||
T* Span<T>::data() const { | ||
return arr_; | ||
} | ||
|
||
template <class T> | ||
size_t Span<T>::size() const { | ||
return size_; | ||
} | ||
#pragma once | ||
|
||
/*! A limited implementation of std::span. */ | ||
template <class T> | ||
class Span { | ||
public: | ||
Span() = default; | ||
|
||
/*! Create a Span with `n` elements. | ||
* | ||
* \tparam n Number of elements. | ||
* | ||
* \param arr Array. | ||
*/ | ||
template <size_t n> | ||
Span(T (&arr)[n]); | ||
|
||
|
||
T& operator [](size_t const); | ||
T const& operator [](size_t const) const; | ||
|
||
|
||
T* begin(); | ||
T* end(); | ||
T const* begin() const; | ||
T const* end() const; | ||
|
||
|
||
/*! Get the underlying data. | ||
* | ||
* \return data. | ||
*/ | ||
T* data() const; | ||
|
||
/*! Get the number of elements. | ||
* | ||
* \return Span size. | ||
*/ | ||
size_t size() const; | ||
|
||
private: | ||
T* arr_ {nullptr}; | ||
size_t size_ {0}; | ||
}; | ||
|
||
|
||
template <class T> | ||
template <size_t n> | ||
Span<T>::Span(T (&arr)[n]) : arr_ {arr}, size_ {n} {} | ||
|
||
|
||
template <class T> | ||
T& Span<T>::operator [](size_t const idx) { | ||
return arr_[idx]; | ||
} | ||
|
||
template <class T> | ||
T const& Span<T>::operator [](size_t const idx) const { | ||
return arr_[idx]; | ||
} | ||
|
||
|
||
template <class T> | ||
T* Span<T>::begin() { | ||
return arr_; | ||
} | ||
|
||
template <class T> | ||
T* Span<T>::end() { | ||
return arr_ + size_; | ||
} | ||
|
||
template <class T> | ||
T const* Span<T>::begin() const { | ||
return arr_; | ||
} | ||
|
||
template <class T> | ||
T const* Span<T>::end() const { | ||
return arr_ + size_; | ||
} | ||
|
||
|
||
template <class T> | ||
T* Span<T>::data() const { | ||
return arr_; | ||
} | ||
|
||
template <class T> | ||
size_t Span<T>::size() const { | ||
return size_; | ||
} |