MySQL  8.0.17
Source Code Documentation
template_utils.h File Reference
#include <stddef.h>
#include "my_dbug.h"

Go to the source code of this file.

Classes

struct  ReturnValueOrError< VALUE_TYPE >
 Utility to allow returning values from functions which can fail (until we have std::optional). More...
 

Functions

template<typename Container_type >
void delete_container_pointers (Container_type &container)
 Clears a container, but deletes all objects that the elements point to first. More...
 
template<typename Container_type >
void my_free_container_pointers (Container_type &container)
 Clears a container, but frees all objects that the elements point to first. More...
 
template<typename T >
pointer_cast (void *p)
 Casts from one pointer type, to another, without using reinterpret_cast or C-style cast: foo f; bar *b= pointer_cast<bar>(f); This avoids having to do: foo f; bar *b= static_cast<bar>(static_cast<void*>(f));. More...
 
template<typename T >
const T pointer_cast (const void *p)
 
template<typename Target , typename Source >
Target down_cast (Source *arg)
 Casts from one pointer type to another in a type hierarchy. More...
 
template<typename Target , typename Source >
Target down_cast (Source &arg)
 Casts from one reference type to another in a type hierarchy. More...
 
template<typename To >
To implicit_cast (To x)
 Sometimes the compiler insists that types be the same and does not do any implicit conversion. More...
 

Function Documentation

◆ delete_container_pointers()

template<typename Container_type >
void delete_container_pointers ( Container_type &  container)

Clears a container, but deletes all objects that the elements point to first.

Template Parameters
Container_typeContainer of pointers.

◆ down_cast() [1/2]

template<typename Target , typename Source >
Target down_cast ( Source *  arg)
inline

Casts from one pointer type to another in a type hierarchy.

In debug mode, we verify the cast is indeed legal.

Template Parameters
TargetThe descendent type, must be a pointer type.
SourceThe parent type.
Parameters
argThe pointer to be down-cast.
Returns
A pointer of type Target.

◆ down_cast() [2/2]

template<typename Target , typename Source >
Target down_cast ( Source &  arg)
inline

Casts from one reference type to another in a type hierarchy.

In debug mode, we verify the cast is indeed legal.

Template Parameters
TargetThe descendent type, must be a reference type.
SourceThe parent type.
Parameters
argThe reference to be down-cast.
Returns
A reference of type Target.

◆ implicit_cast()

template<typename To >
To implicit_cast ( To  x)
inline

Sometimes the compiler insists that types be the same and does not do any implicit conversion.

For example: Derived1 *a; Derived2 *b; // Derived1 and 2 are children classes of Base Base *x= cond ? a : b; // Error, need to force a cast.

Use: Base x= cond ? implicit_cast<Base>(a) : implicit_cast<Base*>(b); static_cast would work too, but would be less safe (allows any pointer-to-pointer conversion, not only up-casts).

◆ my_free_container_pointers()

template<typename Container_type >
void my_free_container_pointers ( Container_type &  container)

Clears a container, but frees all objects that the elements point to first.

Template Parameters
Container_typeContainer of pointers.

◆ pointer_cast() [1/2]

template<typename T >
T pointer_cast ( void *  p)
inline

Casts from one pointer type, to another, without using reinterpret_cast or C-style cast: foo f; bar *b= pointer_cast<bar>(f); This avoids having to do: foo f; bar *b= static_cast<bar>(static_cast<void*>(f));.

◆ pointer_cast() [2/2]

template<typename T >
const T pointer_cast ( const void *  p)
inline