arg_router  1.4.0
C++ command line argument parsing and routing
short_name.hpp
1 // Copyright (C) 2022 by Camden Mannett.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
4 
5 #pragma once
6 
7 #include "arg_router/policy/policy.hpp"
9 
10 namespace arg_router::policy
11 {
27 template <typename S>
29 {
30 public:
32  using string_type = S;
33 
38  constexpr explicit short_name_t([[maybe_unused]] S str = {}) noexcept {}
39 
44  [[nodiscard]] constexpr static std::string_view short_name() noexcept { return S::get(); }
45 
46 private:
47  using full_name_type = AR_STRING_SV(config::short_prefix)::append_t<S>;
48 
49  static_assert(utility::utf8::count(short_name()) == 1, "Short name must only be one character");
50  static_assert(full_name_type::get() != config::long_prefix,
51  "Short name with short prefix cannot match the long prefix");
52 };
53 
58 template <char S>
59 constexpr auto short_name = short_name_t<AR_STRING(S)>{};
60 
65 template <typename S>
66 constexpr auto short_name_utf8 = short_name_t<S>{};
67 
68 template <typename S>
69 struct is_policy<short_name_t<S>> : std::true_type {
70 };
71 } // namespace arg_router::policy
constexpr short_name_t([[maybe_unused]] S str={}) noexcept
Definition: short_name.hpp:38
constexpr static std::string_view short_name() noexcept
Definition: short_name.hpp:44
constexpr auto short_prefix
Definition: config.hpp:58
constexpr auto long_prefix
Definition: config.hpp:52
constexpr auto short_name_utf8
Definition: short_name.hpp:66
constexpr auto short_name
Definition: short_name.hpp:59
constexpr std::size_t count(std::string_view str) noexcept
Definition: utf8.hpp:278