~nabijaczleweli/voreutils

ref: 8f2234246abc6a7ede18496533030b14082f5d68 voreutils/include/vore-optarg -rw-r--r-- 1018 bytes
8f223424наб Add unlink 3 months ago
                                                                                
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-License-Identifier: 0BSD


#pragma once

#include <iterator>


namespace vore {
	template <class T>
	struct backward {
		T & c;

		constexpr auto begin() const noexcept { return std::rbegin(c); }
		constexpr auto end() const noexcept { return std::rend(c); }
	};

	template <class T>
	backward(T &) -> backward<T>;
	template <class T>
	backward(const T &) -> backward<const T>;
}

namespace vore::opt {
	class args {
	public:
		using iterator = const char * const *;

		constexpr args(const char * const * argv) noexcept : b(argv), e(argv) {
			while(*e)
				++e;
		}

		constexpr args(const args &) noexcept = default;
		constexpr args(args &&) noexcept      = default;

		constexpr iterator begin() const noexcept { return b; }
		constexpr iterator end() const noexcept { return e; }

		constexpr auto rbegin() const noexcept { return std::reverse_iterator{e}; }
		constexpr auto rend() const noexcept { return std::reverse_iterator{b}; }

	private:
		const char * const * b;
		const char * const * e;
	};
}