virthttp  0.0
libvirt http interface
utils.hpp
Go to the documentation of this file.
1 //
2 // Created by hugo on 30.01.19.
3 //
4 #pragma once
5 
6 #include <algorithm>
7 #include <tuple>
8 #include <type_traits>
9 #include "virt_wrap/utility.hpp"
10 
11 template <class T> struct TypeVal { using Type = T; };
12 template <class T> TypeVal<T> t_{};
13 
14 template <class T, class U> struct TypePair {
15  using First = T;
16  using Second = U;
17 };
18 
19 template <class T, class U> TypePair<T, U> tp{};
20 
21 template <class T> struct TypeIdentity { using type = T; };
22 
23 template <class T> constexpr auto ti = TypeIdentity<T>{};
24 
25 constexpr auto pow10(std::size_t n) {
26  auto ret = 1u;
27  while (n--)
28  ret *= 10;
29  return ret;
30 }
31 
32 constexpr unsigned strntou(const char* str, std::size_t len) {
33  auto ret = 0u;
34  for (auto i = 0u; i < len; ++i)
35  ret += (str[i] - '0') * pow10(len - i - 1);
36  return ret;
37 }
38 
39 template <typename Container, typename T> unsigned reverse_search(const Container& c, const T& e) {
40  const auto it = std::find(c.begin(), c.end(), e);
41  return static_cast<unsigned>(std::distance(c.begin(), it));
42 }
TypePair< T, U > tp
Definition: utils.hpp:19
Definition: utils.hpp:11
unsigned reverse_search(const Container &c, const T &e)
Definition: utils.hpp:39
Definition: utils.hpp:14
T Type
Definition: utils.hpp:11
T type
Definition: utils.hpp:21
U Second
Definition: utils.hpp:16
Definition: utils.hpp:21
constexpr unsigned strntou(const char *str, std::size_t len)
Definition: utils.hpp:32
TypeVal< T > t_
Definition: utils.hpp:12
constexpr auto ti
Definition: utils.hpp:23
constexpr auto pow10(std::size_t n)
Definition: utils.hpp:25
constexpr InputIt find(InputIt first, InputIt last, const T &value)
Definition: cexpr_algs.hpp:4
T First
Definition: utils.hpp:15