23#ifndef TEMPLATE_UTILS_INCLUDED
24#define TEMPLATE_UTILS_INCLUDED
42template <
typename Container_type>
44 typename Container_type::iterator it1 =
container.begin();
45 typename Container_type::iterator it2 =
container.end();
46 for (; it1 != it2; ++it1) {
56template <
typename Container_type>
58 typename Container_type::iterator it1 =
container.begin();
59 typename Container_type::iterator it2 =
container.end();
60 for (; it1 != it2; ++it1) {
75 return static_cast<T
>(
p);
80 return static_cast<T
>(
p);
94template <
typename Target,
typename Source>
99 "Do not use down_cast for upcasts; use implicit_cast or nothing");
100 assert(
nullptr !=
dynamic_cast<Target
>(arg));
101 return static_cast<Target
>(arg);
115template <
typename Target,
typename Source>
123 "Do not use down_cast for upcasts; use implicit_cast or nothing");
126 return static_cast<Target
>(arg);
141template <
typename To>
150template <
class VALUE_TYPE>
162template <
class T,
size_t N>
187template <
class InputIt,
class Pred,
class Action>
189 while (first !=
last) {
190 InputIt split = std::find_if(first,
last, std::forward<Pred>(pred));
193 if (split ==
last)
return;
211template <
class InputIt,
class Pred>
213 return std::find_if_not(std::make_reverse_iterator(
last),
214 std::make_reverse_iterator(first),
215 std::forward<Pred>(pred))
232template <
class InputIt,
class Pred>
235 InputIt f = std::find_if_not(first,
last, std::forward<Pred>(pred));
240const auto IsSpace = [](
char c) {
return isspace(c); };
241const auto IsComma = [](
char c) {
return c ==
','; };
const char * p
Definition: ctype-mb.cc:1236
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:80
std::atomic< Type > N
Definition: ut0counter.h:224
Definition: atomics_array.h:38
Definition: template_utils.h:167
const auto IsSpace
Convenience lambdas for common predicates.
Definition: template_utils.h:240
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:188
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:212
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:233
const auto IsComma
Definition: template_utils.h:241
message Source
Definition: replication_asynchronous_connection_failover.proto:29
message Action
Definition: replication_group_member_actions.proto:29
required string type
Definition: replication_group_member_actions.proto:33
repeated Action action
Definition: replication_group_member_actions.proto:42
Utility to allow returning values from functions which can fail (until we have std::optional).
Definition: template_utils.h:151
VALUE_TYPE value
Value returned from function in the normal case.
Definition: template_utils.h:153
bool error
True if an error occurred.
Definition: template_utils.h:156
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:142
Target down_cast(Source *arg)
Casts from one pointer type to another in a type hierarchy.
Definition: template_utils.h:95
constexpr size_t array_elements(T(&)[N]) noexcept
Number of elements in a constant C array.
Definition: template_utils.h:163
void delete_container_pointers(Container_type &container)
Clears a container, but deletes all objects that the elements point to first.
Definition: template_utils.h:43
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:74
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:57