24#ifndef TEMPLATE_UTILS_INCLUDED
25#define TEMPLATE_UTILS_INCLUDED
43template <
typename Container_type>
45 typename Container_type::iterator it1 =
container.begin();
46 typename Container_type::iterator it2 =
container.end();
47 for (; it1 != it2; ++it1) {
57template <
typename Container_type>
59 typename Container_type::iterator it1 =
container.begin();
60 typename Container_type::iterator it2 =
container.end();
61 for (; it1 != it2; ++it1) {
76 return static_cast<T
>(
p);
81 return static_cast<T
>(
p);
95template <
typename Target,
typename Source>
100 "Do not use down_cast for upcasts; use implicit_cast or nothing");
101 assert(
nullptr !=
dynamic_cast<Target
>(arg));
102 return static_cast<Target
>(arg);
116template <
typename Target,
typename Source>
124 "Do not use down_cast for upcasts; use implicit_cast or nothing");
127 return static_cast<Target
>(arg);
142template <
typename To>
151template <
class VALUE_TYPE>
163template <
class T,
size_t N>
188template <
class InputIt,
class Pred,
class Action>
190 while (first !=
last) {
191 InputIt split = std::find_if(first,
last, std::forward<Pred>(pred));
194 if (split ==
last)
return;
212template <
class InputIt,
class Pred>
214 return std::find_if_not(std::make_reverse_iterator(
last),
215 std::make_reverse_iterator(first),
216 std::forward<Pred>(pred))
233template <
class InputIt,
class Pred>
236 InputIt f = std::find_if_not(first,
last, std::forward<Pred>(pred));
241const auto IsSpace = [](
char c) {
return isspace(c); };
242const auto IsComma = [](
char c) {
return c ==
','; };
const char * p
Definition: ctype-mb.cc:1237
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:81
std::atomic< Type > N
Definition: ut0counter.h:225
Definition: atomics_array.h:39
Definition: template_utils.h:168
const auto IsSpace
Convenience lambdas for common predicates.
Definition: template_utils.h:241
void Split(InputIt first, InputIt last, Pred &&pred, Action &&action)
Split a range into sub ranges delimited by elements satisfying a predicate.
Definition: template_utils.h:189
InputIt FindTrimmedEnd(InputIt first, InputIt last, Pred &&pred)
Search backwards for the first occurrence of an element which does not satisfy the trimming predicate...
Definition: template_utils.h:213
std::pair< InputIt, InputIt > FindTrimmedRange(InputIt first, InputIt last, Pred &&pred)
Searches for a sub range such that no elements before or after fail to satisfy the trimming predicate...
Definition: template_utils.h:234
const auto IsComma
Definition: template_utils.h:242
message Source
Definition: replication_asynchronous_connection_failover.proto:30
message Action
Definition: replication_group_member_actions.proto:30
required string type
Definition: replication_group_member_actions.proto:34
repeated Action action
Definition: replication_group_member_actions.proto:43
Utility to allow returning values from functions which can fail (until we have std::optional).
Definition: template_utils.h:152
VALUE_TYPE value
Value returned from function in the normal case.
Definition: template_utils.h:154
bool error
True if an error occurred.
Definition: template_utils.h:157
To implicit_cast(To x)
Sometimes the compiler insists that types be the same and does not do any implicit conversion.
Definition: template_utils.h:143
Target down_cast(Source *arg)
Casts from one pointer type to another in a type hierarchy.
Definition: template_utils.h:96
constexpr size_t array_elements(T(&)[N]) noexcept
Number of elements in a constant C array.
Definition: template_utils.h:164
void delete_container_pointers(Container_type &container)
Clears a container, but deletes all objects that the elements point to first.
Definition: template_utils.h:44
T pointer_cast(void *p)
Casts from one pointer type, to another, without using reinterpret_cast or C-style cast: foo f; bar *...
Definition: template_utils.h:75
void my_free_container_pointers(Container_type &container)
Clears a container, but frees all objects that the elements point to first.
Definition: template_utils.h:58