Skip to content

Commit

Permalink
Added provisional implementation of C++14's cbegin/cend/rbegin/rend
Browse files Browse the repository at this point in the history
  • Loading branch information
evaleev committed Jul 28, 2014
1 parent 7fdd0fb commit 02675d8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 57 deletions.
72 changes: 20 additions & 52 deletions btas/array_adaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,58 +139,7 @@ namespace btas {
namespace std {

template <typename T, size_t N>
auto cbegin(const std::array<T,N>& x) -> decltype(x.cbegin()) {
return x.cbegin();
}
template <typename T, size_t N>
auto cend(const std::array<T,N>& x) -> decltype(x.cend()) {
return x.cend();
}
template <typename T, size_t N>
auto rbegin(std::array<T,N>& x) -> decltype(x.rbegin()) {
return x.rbegin();
}
template <typename T, size_t N>
auto rend(std::array<T,N>& x) -> decltype(x.rend()) {
return x.rend();
}

template <typename T>
auto cbegin(const btas::varray<T>& x) -> decltype(x.cbegin()) {
return x.cbegin();
}
template <typename T>
auto cend(const btas::varray<T>& x) -> decltype(x.cend()) {
return x.cend();
}
template <typename T>
auto rbegin(btas::varray<T>& x) -> decltype(x.rbegin()) {
return x.rbegin();
}
template <typename T>
auto rend(btas::varray<T>& x) -> decltype(x.rend()) {
return x.rend();
}

template <typename T>
auto cbegin(const std::vector<T>& x) -> decltype(x.cbegin()) {
return x.cbegin();
}
template <typename T>
auto cend(const std::vector<T>& x) -> decltype(x.cend()) {
return x.cend();
}
template <typename T>
auto rbegin(std::vector<T>& x) -> decltype(x.rbegin()) {
return x.rbegin();
}
template <typename T>
auto rend(std::vector<T>& x) -> decltype(x.rend()) {
return x.rend();
}

template <typename T, size_t N>
const T* cbegin(const T (&x)[N]) {
const T* cbegin(const T(&x)[N]) {
return &x[0];
}
template <typename T, size_t N>
Expand Down Expand Up @@ -219,6 +168,25 @@ namespace std {
return x;
}

#if __cplusplus == 201103L // add useful bits to make transition to C++14 easier
template <typename C>
constexpr auto cbegin(const C& x) -> decltype(std::begin(x)) {
return std::begin(x);
}
template <typename C>
constexpr auto cend(const C& x) -> decltype(std::end(x)) {
return std::end(x);
}
template <typename C>
auto rbegin(C& x) -> decltype(x.rbegin()) {
return x.rbegin();
}
template <typename C>
auto rend(C& x) -> decltype(x.rend()) {
return x.rend();
}
#endif

template <typename T>
struct make_unsigned<std::vector<T> > {
typedef std::vector<typename make_unsigned<T>::type > type;
Expand Down
5 changes: 0 additions & 5 deletions btas/util/sequence_adaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ namespace std {
return reference_wrapper<const btas::infinite_sequence_adaptor<_T*>>(t);
}

template <typename T>
auto cbegin(const btas::infinite_sequence_adaptor<T>& x) -> decltype(x.cbegin()) {
return x.cbegin();
}

}

#endif /* __BTAS_UTIL_SEQUENCEADAPTOR_H_ */

0 comments on commit 02675d8

Please sign in to comment.