From 02675d8c66bad7540d81e83d6c2ecfd7730be8a6 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Mon, 28 Jul 2014 09:58:19 -0400 Subject: [PATCH] Added provisional implementation of C++14's cbegin/cend/rbegin/rend --- btas/array_adaptor.h | 72 ++++++++++-------------------------- btas/util/sequence_adaptor.h | 5 --- 2 files changed, 20 insertions(+), 57 deletions(-) diff --git a/btas/array_adaptor.h b/btas/array_adaptor.h index 25011eef..8cd501ec 100644 --- a/btas/array_adaptor.h +++ b/btas/array_adaptor.h @@ -139,58 +139,7 @@ namespace btas { namespace std { template - auto cbegin(const std::array& x) -> decltype(x.cbegin()) { - return x.cbegin(); - } - template - auto cend(const std::array& x) -> decltype(x.cend()) { - return x.cend(); - } - template - auto rbegin(std::array& x) -> decltype(x.rbegin()) { - return x.rbegin(); - } - template - auto rend(std::array& x) -> decltype(x.rend()) { - return x.rend(); - } - - template - auto cbegin(const btas::varray& x) -> decltype(x.cbegin()) { - return x.cbegin(); - } - template - auto cend(const btas::varray& x) -> decltype(x.cend()) { - return x.cend(); - } - template - auto rbegin(btas::varray& x) -> decltype(x.rbegin()) { - return x.rbegin(); - } - template - auto rend(btas::varray& x) -> decltype(x.rend()) { - return x.rend(); - } - - template - auto cbegin(const std::vector& x) -> decltype(x.cbegin()) { - return x.cbegin(); - } - template - auto cend(const std::vector& x) -> decltype(x.cend()) { - return x.cend(); - } - template - auto rbegin(std::vector& x) -> decltype(x.rbegin()) { - return x.rbegin(); - } - template - auto rend(std::vector& x) -> decltype(x.rend()) { - return x.rend(); - } - - template - const T* cbegin(const T (&x)[N]) { + const T* cbegin(const T(&x)[N]) { return &x[0]; } template @@ -219,6 +168,25 @@ namespace std { return x; } +#if __cplusplus == 201103L // add useful bits to make transition to C++14 easier + template + constexpr auto cbegin(const C& x) -> decltype(std::begin(x)) { + return std::begin(x); + } + template + constexpr auto cend(const C& x) -> decltype(std::end(x)) { + return std::end(x); + } + template + auto rbegin(C& x) -> decltype(x.rbegin()) { + return x.rbegin(); + } + template + auto rend(C& x) -> decltype(x.rend()) { + return x.rend(); + } +#endif + template struct make_unsigned > { typedef std::vector::type > type; diff --git a/btas/util/sequence_adaptor.h b/btas/util/sequence_adaptor.h index 9e30a35d..ceb859fb 100644 --- a/btas/util/sequence_adaptor.h +++ b/btas/util/sequence_adaptor.h @@ -122,11 +122,6 @@ namespace std { return reference_wrapper>(t); } - template - auto cbegin(const btas::infinite_sequence_adaptor& x) -> decltype(x.cbegin()) { - return x.cbegin(); - } - } #endif /* __BTAS_UTIL_SEQUENCEADAPTOR_H_ */