1 // 2 // backwards.h 3 // Context Free 4 // 5 // Copyright (c) 2018, Adam Nevraumont 6 // Creative Commons CC-BY-SA license 7 // https://creativecommons.org/licenses/by-sa/4.0/ 8 // 9 10 #ifndef backwards_h 11 #define backwards_h 12 13 template<class R> 14 struct backwards_t { 15 R r; beginbackwards_t16 constexpr auto begin() const { using std::rbegin; return rbegin(r); } beginbackwards_t17 constexpr auto begin() { using std::rbegin; return rbegin(r); } endbackwards_t18 constexpr auto end() const { using std::rend; return rend(r); } endbackwards_t19 constexpr auto end() { using std::rend; return rend(r); } 20 }; 21 // Do NOT, I repeat do NOT change this to `backwards_t<std::decay_t<R>>. 22 // This code is using forwarding references in a clever way. 23 template<class R> backwards(R && r)24constexpr backwards_t<R> backwards( R&& r ) { return {std::forward<R>(r)}; } 25 26 27 #endif /* backwards_h */ 28