-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: Ibb653c89a556c3bb32ce891e786719f70b56431f
- Loading branch information
1 parent
08f80d1
commit 7c390fa
Showing
3 changed files
with
130 additions
and
13 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,34 +1,83 @@ | ||
/* | ||
* Copyright (C) 2017-2018 Intel Corporation | ||
* Copyright (C) 2017-2019 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <iterator> | ||
|
||
namespace OCLRT { | ||
|
||
template <typename T> | ||
template <typename DataType> | ||
struct Range { | ||
Range(T *base, size_t count) | ||
: Beg(base), End(base + count) { | ||
using iterator = DataType *; | ||
using const_iterator = const DataType *; | ||
using reverse_iterator = std::reverse_iterator<iterator>; | ||
using const_reverse_iterator = std::reverse_iterator<const_iterator>; | ||
|
||
Range(DataType *base, size_t count) | ||
: begIt(base), endIt(base + count) { | ||
} | ||
|
||
template <typename SequentialContainerT, typename BeginT = decltype(((SequentialContainerT *)nullptr)->size())> | ||
Range(SequentialContainerT &container) | ||
: Range(&*container.begin(), container.size()) { | ||
} | ||
|
||
template <typename T, size_t S> | ||
Range(T (&base)[S]) | ||
: Range(&base[0], S) { | ||
} | ||
|
||
iterator begin() { | ||
return begIt; | ||
} | ||
|
||
iterator end() { | ||
return endIt; | ||
} | ||
|
||
const_iterator begin() const { | ||
return begIt; | ||
} | ||
|
||
const_iterator end() const { | ||
return endIt; | ||
} | ||
|
||
reverse_iterator rbegin() { | ||
return reverse_iterator(end()); | ||
} | ||
|
||
const_reverse_iterator rbegin() const { | ||
return const_reverse_iterator(end()); | ||
} | ||
|
||
reverse_iterator rend() { | ||
return reverse_iterator(end()) + (endIt - begIt); | ||
} | ||
|
||
const_reverse_iterator rend() const { | ||
return const_reverse_iterator(end()) + (endIt - begIt); | ||
} | ||
|
||
T *begin() { | ||
return Beg; | ||
bool empty() const { | ||
return begIt == endIt; | ||
} | ||
|
||
T *end() { | ||
return End; | ||
size_t size() const { | ||
return endIt - begIt; | ||
} | ||
|
||
T *Beg; | ||
T *End; | ||
iterator begIt; | ||
iterator endIt; | ||
}; | ||
|
||
template <typename T> | ||
Range<T> CreateRange(T *base, size_t count) { | ||
inline Range<T> CreateRange(T *base, size_t count) { | ||
return Range<T>(base, count); | ||
} | ||
} // namespace OCLRT |
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
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