DocWire SDK
DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, document analysis. Offline processing possible for security and confidentiality
named.h
1 /*********************************************************************************************************************************************/
2 /* DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. */
3 /* Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, */
4 /* document analysis. Offline processing possible for security and confidentiality */
5 /* */
6 /* Copyright (c) SILVERCODERS Ltd, http://silvercoders.com */
7 /* Project homepage: https://github.com/docwire/docwire */
8 /* */
9 /* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-DocWire-Commercial */
10 /*********************************************************************************************************************************************/
11 #ifndef DOCWIRE_NAMED_H
12 #define DOCWIRE_NAMED_H
13 #include <string_view>
14 #include <utility>
15 #include <tuple>
16 #include <type_traits>
17 
21 namespace docwire::named
22 {
26  template <typename T>
27  struct value
28  {
30  std::string_view name;
32  T value;
33  };
34 
35  template <size_t I, typename T>
36  [[nodiscard]] constexpr decltype(auto) get(value<T>& v) noexcept
37  {
38  if constexpr (I == 0) return (v.name);
39  else return (v.value);
40  }
41 
42  template <size_t I, typename T>
43  [[nodiscard]] constexpr decltype(auto) get(const value<T>& v) noexcept
44  {
45  if constexpr (I == 0) return (v.name);
46  else return (v.value);
47  }
48 
49  template <size_t I, typename T>
50  [[nodiscard]] constexpr decltype(auto) get(value<T>&& v) noexcept
51  {
52  if constexpr (I == 0) return std::move(v.name);
53  else return std::move(v.value);
54  }
55 
59  struct variable
60  {
61  const std::string_view name;
62 
63  template <typename T>
64  [[nodiscard]] constexpr auto operator=(T&& val) const noexcept(noexcept(value<std::decay_t<T>>{name, std::forward<T>(val)}))
65  {
66  return value<std::decay_t<T>>{name, std::forward<T>(val)};
67  }
68  };
69 
70  inline namespace literals
71  {
76  [[nodiscard]] constexpr variable operator""_v(const char* str, size_t len) noexcept
77  {
78  return {std::string_view{str, len}};
79  }
80  }
81 }
82 
83 namespace docwire
84 {
85  // Bring the _v literal into the docwire namespace for convenience.
86  using namespace docwire::named::literals;
87 }
88 
89 namespace std
90 {
94  template <typename T>
95  struct tuple_size<docwire::named::value<T>> : std::integral_constant<size_t, 2> {};
96 
100  template <size_t I, typename T>
101  struct tuple_element<I, docwire::named::value<T>>
102  {
103  static_assert(I < 2, "index out of range for docwire::named::value");
104  using type = std::conditional_t<I == 0, std::string_view, T>;
105  };
106 }
107 
108 #endif // DOCWIRE_NAMED_H
Utilities for named parameters.
Definition: named.h:22
The main namespace for the DocWire SDK.
Definition: ai_elements.h:19
A named value wrapper.
Definition: named.h:28
T value
The value of the parameter.
Definition: named.h:32
std::string_view name
The name of the parameter.
Definition: named.h:30
A helper to create named values using assignment syntax.
Definition: named.h:60