packio
arg.h
Go to the documentation of this file.
1 // This Source Code Form is subject to the terms of the Mozilla Public
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4 
5 #ifndef PACKIO_ARG_H
6 #define PACKIO_ARG_H
7 
10 
11 #include <string>
12 #include <string_view>
13 
14 namespace packio {
15 
16 class arg {
17 public:
18  template <typename T>
19  struct with_value {
20  const std::string name;
21  T value;
22  };
23 
24  explicit constexpr arg(std::string_view name) : name_{name} {}
25 
26  template <typename T>
27  constexpr with_value<T> operator=(T&& value)
28  {
29  return {std::string{name_}, std::forward<T>(value)};
30  }
31 
32 private:
33  std::string_view name_;
34 };
35 
36 template <typename T>
37 struct is_arg_impl : std::false_type {
38 };
39 
40 template <typename T>
41 struct is_arg_impl<arg::with_value<T>> : std::true_type {
42 };
43 
44 template <typename T>
45 struct is_arg : is_arg_impl<std::decay_t<T>> {
46 };
47 
48 template <typename T>
49 constexpr bool is_arg_v = is_arg<T>::value;
50 
51 namespace arg_literals {
52 
53 constexpr arg operator"" _arg(const char* str, std::size_t)
54 {
55  return arg{str};
56 }
57 
58 } // arg_literals
59 
60 } // packio
61 
62 #endif // PACKIO_INTERNAL_ARG_H
packio
Definition: arg.h:14