1 #pragma once
2 
3 #include <iterator>
4 #include <utility>
5 
6 namespace sdbusplus
7 {
8 namespace utility
9 {
10 
11 /** has_const_iterator - Determine if type has const iterator
12  *
13  *  @tparam T - Type to be tested.
14  *
15  *  @value A value as to whether or not the type supports iteration
16  */
17 template <typename T>
18 struct has_const_iterator
19 {
20   private:
21     typedef char yes;
22     typedef struct
23     {
24         char array[2];
25     } no;
26 
27     template <typename C>
28     static constexpr yes test(decltype(std::cbegin(std::declval<C>()))*);
29     template <typename C>
30     static constexpr no test(...);
31 
32   public:
33     static constexpr bool value = sizeof(test<T>(nullptr)) == sizeof(yes);
34 };
35 
36 template <typename T>
37 inline constexpr bool has_const_iterator_v = has_const_iterator<T>::value;
38 
39 /** has_emplace_method - Determine if type has a method template named emplace
40  *
41  *  @tparam T - Type to be tested.
42  *
43  *  @value A value as to whether or not the type has an emplace method
44  */
45 template <typename T>
46 struct has_emplace_method
47 {
48   private:
49     struct dummy
50     {};
51 
52     template <typename C, typename P>
53     static constexpr auto
54         test(P* p) -> decltype(std::declval<C>().emplace(*p), std::true_type());
55 
56     template <typename, typename>
57     static std::false_type test(...);
58 
59   public:
60     static constexpr bool value =
61         std::is_same_v<std::true_type, decltype(test<T, dummy>(nullptr))>;
62 };
63 
64 template <typename T>
65 inline constexpr bool has_emplace_method_v = has_emplace_method<T>::value;
66 
67 /** has_emplace_method - Determine if type has a method template named
68  * emplace_back
69  *
70  *  @tparam T - Type to be tested.
71  *
72  *  @value A value as to whether or not the type has an emplace_back method
73  */
74 template <typename T>
75 struct has_emplace_back_method
76 {
77   private:
78     struct dummy
79     {};
80 
81     template <typename C, typename P>
82     static constexpr auto test(P* p)
83         -> decltype(std::declval<C>().emplace_back(*p), std::true_type());
84 
85     template <typename, typename>
86     static std::false_type test(...);
87 
88   public:
89     static constexpr bool value =
90         std::is_same_v<std::true_type, decltype(test<T, dummy>(nullptr))>;
91 };
92 
93 template <typename T>
94 inline constexpr bool has_emplace_back_method_v =
95     has_emplace_back_method<T>::value;
96 
97 } // namespace utility
98 } // namespace sdbusplus
99