File: backwards.h

package info (click to toggle)
contextfree 3.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,260 kB
  • sloc: cpp: 37,992; lex: 414; makefile: 123; sh: 43; python: 34
file content (27 lines) | stat: -rw-r--r-- 790 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//
//  backwards.h
//  Context Free
//
// Copyright (c) 2018, Adam Nevraumont
// Creative Commons CC-BY-SA license
// https://creativecommons.org/licenses/by-sa/4.0/
//

#ifndef backwards_h
#define backwards_h

template<class R>
struct backwards_t {
    R r;
    constexpr auto begin() const { using std::rbegin; return rbegin(r); }
    constexpr auto begin() { using std::rbegin; return rbegin(r); }
    constexpr auto end() const { using std::rend; return rend(r); }
    constexpr auto end() { using std::rend; return rend(r); }
};
// Do NOT, I repeat do NOT change this to `backwards_t<std::decay_t<R>>.
// This code is using forwarding references in a clever way.
template<class R>
constexpr backwards_t<R> backwards( R&& r ) { return {std::forward<R>(r)}; }


#endif /* backwards_h */