Main MRPT website > C++ reference
MRPT logo
Classes | Namespaces | Macros | Functions
STL extensions and metaprogramming

Detailed Description

Collaboration diagram for STL extensions and metaprogramming:

Classes

class  mrpt::utils::bimap< KEY, VALUE >
 A bidirectional version of std::map, declared as bimap<KEY,VALUE> and which actually contains two std::map's, one for keys and another for values. More...
 
class  mrpt::utils::circular_buffer< T >
 A circular buffer of fixed size (defined at construction-time), implemented with a std::vector as the underlying storage. More...
 
class  mrpt::utils::list_searchable< T >
 This class implements a STL container with features of both, a std::set and a std::list. More...
 
class  mrpt::utils::map_as_vector< KEY, VALUE, VECTOR_T >
 A STL-like container which looks and behaves (almost exactly) like a std::map<> but is implemented as a linear std::vector<> indexed by KEY. More...
 
struct  mrpt::utils::metaprogramming::ObjectDelete
 An object for deleting pointers (intended for STL algorithms) More...
 
struct  mrpt::utils::metaprogramming::ObjectClear
 An object for clearing an object (invokes its method "->clear()") given a pointer or smart-pointer, intended for being used in STL algorithms. More...
 
struct  mrpt::utils::metaprogramming::ObjectClear2
 An object for clearing an object (invokes its method ".clear()") given a pointer or smart-pointer, intended for being used in STL algorithms. More...
 
struct  mrpt::utils::metaprogramming::ObjectClearSecond
 An object for clearing an object->second (invokes its method "clear()") given a pointer or smart-pointer, intended for being used in STL algorithms. More...
 
struct  mrpt::utils::metaprogramming::ObjectConvert< TARGET_TYPE >
 An object for transforming between types/classes, intended for being used in STL algorithms. More...
 
struct  mrpt::utils::metaprogramming::ObjectMakeUnique
 An object for making smart pointers unique (ie, making copies if necessary), intended for being used in STL algorithms. More...
 
struct  mrpt::utils::metaprogramming::ObjectPairMakeUnique
 An object for making smart pointers unique (ie, making copies if necessary), intended for being used in STL algorithms. More...
 
struct  mrpt::utils::metaprogramming::ObjectClearUnique
 An object for making smart pointers unique (ie, making copies if necessary), intended for being used in STL algorithms. More...
 
struct  mrpt::utils::metaprogramming::ObjectReadFromStream
 An object for reading objects from a stream, intended for being used in STL algorithms. More...
 
struct  mrpt::utils::metaprogramming::ObjectWriteToStream
 An object for writing objects to a stream, intended for being used in STL algorithms. More...
 
class  mrpt::utils::metaprogramming::MemoryBypasserIterator< T, U >
 This class bypasses pointer access in iterators to pointers, thus allowing the use of algorithms that expect an object of class T with containers of T*. More...
 
class  mrpt::utils::metaprogramming::BinaryMemberFunctionWrapper< T, U1, U2, V >
 This template encapsulates a binary member function and a single object into a function expecting the two parameters of the member function. More...
 
class  mrpt::utils::metaprogramming::UnaryMemberFunctionWrapper< T, U, V >
 This template encapsulates an unary member function and a single object into a function expecting the parameter of the member function. More...
 
class  mrpt::utils::metaprogramming::MemberFunctionWrapper< T, V >
 This template encapsulates a member function without arguments and a single object into a function. More...
 
class  mrpt::utils::metaprogramming::NonConstBind1st< Op >
 Equivalent of std::bind1st for functions with non-const arguments. More...
 
class  mrpt::utils::metaprogramming::NonConstBind2nd< Op >
 Equivalent of std::bind2nd for functions with non-const arguments. More...
 
struct  mrpt::utils::ci_less
 A case-insensitive comparator struct for usage within STL containers, eg: map<string,string,ci_less> More...
 
struct  mrpt::utils::map_traits_stdmap
 Traits for using a std::map<> (sparse representation) More...
 
struct  mrpt::utils::map_traits_map_as_vector
 Traits for using a mrpt::utils::map_as_vector<> (dense, fastest representation) More...
 

Namespaces

 mrpt::utils::metaprogramming
 A set of utility objects for metaprogramming with STL algorithms.
 

Macros

#define MRPTSTL_SERIALIZABLE_SEQ_CONTAINER(CONTAINER)
 
#define MRPTSTL_SERIALIZABLE_ASSOC_CONTAINER(CONTAINER)
 

Functions

template<typename T >
void mrpt::utils::metaprogramming::DeleteContainer (T &container)
 A function which deletes a container of pointers. More...
 
template<typename it_src , typename it_dst >
void mrpt::utils::metaprogramming::copy_typecasting (it_src first, it_src last, it_dst target)
 Behaves like std::copy but allows the source and target iterators to be of different types through static typecasting. More...
 
template<typename src_container , typename dst_container >
void mrpt::utils::metaprogramming::copy_container_typecasting (const src_container &src, dst_container &trg)
 Copy all the elements in a container (vector, deque, list) into a different one performing the appropriate typecasting. More...
 
template<typename U , typename T >
MemoryBypasserIterator< T, U > mrpt::utils::metaprogramming::bypassPointer (const T &baseIterator)
 Sintactic sugar for MemoryBypasserIterator. More...
 
template<typename T , typename U1 , typename U2 , typename V >
BinaryMemberFunctionWrapper< T, U1, U2, V > mrpt::utils::metaprogramming::wrapMember (V &obj, T(V::*fun)(U1, U2))
 This function creates a function from an object and a member function. More...
 
template<typename T , typename U , typename V >
UnaryMemberFunctionWrapper< T, U, V > mrpt::utils::metaprogramming::wrapMember (V &obj, T(V::*fun)(U))
 
template<typename T , typename V >
MemberFunctionWrapper< T, V > mrpt::utils::metaprogramming::wrapMember (V &obj, T(V::*fun)(void))
 
template<typename Op >
NonConstBind1st< Op > mrpt::utils::metaprogramming::nonConstBind1st (Op &o, typename Op::first_argument_type &t)
 Use this function instead of directly calling NonConstBind1st. More...
 
template<typename Op >
NonConstBind2nd< Op > mrpt::utils::metaprogramming::nonConstBind2nd (Op &o, typename Op::second_argument_type &t)
 Do not directly use the NonConstBind2nd class directly. More...
 
 mrpt::utils::MRPTSTL_SERIALIZABLE_SEQ_CONTAINER (std::vector) MRPTSTL_SERIALIZABLE_SEQ_CONTAINER(std
 Template method to serialize a STL pair. More...
 
template<class T1 , class T2 >
CStreammrpt::utils::operator>> (CStream &in, std::pair< T1, T2 > &obj)
 Template method to deserialize a STL pair. More...
 
template<class T , class CONTAINER >
size_t mrpt::utils::find_in_vector (const T &value, const CONTAINER &vect)
 Returns the index of the value "T" in the container "vect" (std::vector,std::deque,etc), or string::npos if not found. More...
 
template<class T >
std::list< T >::iterator mrpt::utils::erase_return_next (std::list< T > &cont, typename std::list< T >::iterator &it)
 Calls the standard "erase" method of a STL container, but also returns an iterator to the next element in the container (or end if none) More...
 
template<class K , class V >
std::map< K, V >::iterator mrpt::utils::erase_return_next (std::map< K, V > &cont, typename std::map< K, V >::iterator &it)
 
template<class K , class V >
std::multimap< K, V >::iterator mrpt::utils::erase_return_next (std::multimap< K, V > &cont, typename std::multimap< K, V >::iterator &it)
 
template<class T >
std::set< T >::iterator mrpt::utils::erase_return_next (std::set< T > &cont, typename std::set< T >::iterator &it)
 
template<typename T >
std::string mrpt::utils::sprintf_vector (const char *fmt, const std::vector< T > &V)
 Generates a string for a vector in the format [A,B,C,...] to std::cout, and the fmt string for each vector element. More...
 
template<typename Derived >
std::string mrpt::utils::sprintf_vector (const char *fmt, const Eigen::MatrixBase< Derived > &V)
 
template<typename T >
void mrpt::utils::printf_vector (const char *fmt, const std::vector< T > &V)
 Prints a vector in the format [A,B,C,...] to std::cout, and the fmt string for each vector element. More...
 

Macro Definition Documentation

◆ MRPTSTL_SERIALIZABLE_ASSOC_CONTAINER

#define MRPTSTL_SERIALIZABLE_ASSOC_CONTAINER (   CONTAINER)

Definition at line 96 of file stl_extensions.h.

◆ MRPTSTL_SERIALIZABLE_SEQ_CONTAINER

#define MRPTSTL_SERIALIZABLE_SEQ_CONTAINER (   CONTAINER)
Value:
/** Template method to serialize a sequential STL container */ \
template <class T,class _Ax> \
CStream& operator << (CStream& out, const CONTAINER<T,_Ax> &obj) \
{ \
out << string(#CONTAINER) << TTypeName<T>::get(); \
out << static_cast<uint32_t>(obj.size()); \
for_each( obj.begin(), obj.end(), ObjectWriteToStream(&out) ); \
return out; \
} \
/** Template method to deserialize a sequential STL container */ \
template <class T,class _Ax> \
CStream& operator >> (CStream& in, CONTAINER<T,_Ax> &obj) \
{ \
obj.clear(); \
string pref,stored_T; \
in >> pref; \
if (pref!=#CONTAINER) THROW_EXCEPTION(format("Error: serialized container %s<%s>'s preambles is wrong: '%s'",#CONTAINER,TTypeName<T>::get().c_str(),pref.c_str() )) \
in >> stored_T; \
if (stored_T != TTypeName<T>::get() ) THROW_EXCEPTION(format("Error: serialized container %s< %s != %s >",#CONTAINER,stored_T.c_str(),TTypeName<T>::get().c_str() )) \
uint32_t n; \
in >> n; \
obj.resize(n); \
for_each( obj.begin(), obj.end(), ObjectReadFromStream(&in) ); \
return in; \
}
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
#define THROW_EXCEPTION(msg)
An object for writing objects to a stream, intended for being used in STL algorithms.
class BASE_IMPEXP CStream
Definition: math_frwds.h:54
CStream & operator>>(CStream &in, std::pair< T1, T2 > &obj)
Template method to deserialize a STL pair.

Definition at line 68 of file stl_extensions.h.

Function Documentation

◆ bypassPointer()

template<typename U , typename T >
MemoryBypasserIterator<T,U> mrpt::utils::metaprogramming::bypassPointer ( const T &  baseIterator)
inline

Sintactic sugar for MemoryBypasserIterator.

For example, having the following declarations: vector<double *> vec; void modifyVal(double &v); The following sentence is not legal: for_each(vec.begin(),vec.end(),&modifyVal) But this one is: for_each(bypassPointer(vec.begin()),bypassPointer(vec.end()),&modifyVal)

Definition at line 279 of file metaprogramming.h.

◆ copy_container_typecasting()

template<typename src_container , typename dst_container >
void mrpt::utils::metaprogramming::copy_container_typecasting ( const src_container &  src,
dst_container &  trg 
)
inline

Copy all the elements in a container (vector, deque, list) into a different one performing the appropriate typecasting.

The target container is automatically resized to the appropriate size, and previous contents are lost. This can be used to assign std::vector's of different types:

std::vector<int> vi(10);
std::vector<float> vf;
vf = vi; // Compiler error

Definition at line 192 of file metaprogramming.h.

Referenced by mrpt::opengl::CAngularObservationMesh::FTrace2D< T >::operator()().

◆ copy_typecasting()

template<typename it_src , typename it_dst >
void mrpt::utils::metaprogramming::copy_typecasting ( it_src  first,
it_src  last,
it_dst  target 
)
inline

Behaves like std::copy but allows the source and target iterators to be of different types through static typecasting.

Note
As in std::copy, the target iterator must point to the first "slot" where to put the first transformed element, and sufficient space must be allocated in advance.
See also
copy_container_typecasting

Definition at line 175 of file metaprogramming.h.

◆ DeleteContainer()

template<typename T >
void mrpt::utils::metaprogramming::DeleteContainer ( T &  container)
inline

A function which deletes a container of pointers.

Definition at line 61 of file metaprogramming.h.

◆ erase_return_next() [1/4]

template<class T >
std::list<T>::iterator mrpt::utils::erase_return_next ( std::list< T > &  cont,
typename std::list< T >::iterator it 
)
inline

Calls the standard "erase" method of a STL container, but also returns an iterator to the next element in the container (or end if none)

Definition at line 212 of file stl_extensions.h.

◆ erase_return_next() [2/4]

template<class K , class V >
std::map<K,V>::iterator mrpt::utils::erase_return_next ( std::map< K, V > &  cont,
typename std::map< K, V >::iterator it 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 217 of file stl_extensions.h.

◆ erase_return_next() [3/4]

template<class K , class V >
std::multimap<K,V>::iterator mrpt::utils::erase_return_next ( std::multimap< K, V > &  cont,
typename std::multimap< K, V >::iterator it 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 224 of file stl_extensions.h.

◆ erase_return_next() [4/4]

template<class T >
std::set<T>::iterator mrpt::utils::erase_return_next ( std::set< T > &  cont,
typename std::set< T >::iterator it 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 231 of file stl_extensions.h.

◆ find_in_vector()

template<class T , class CONTAINER >
size_t mrpt::utils::find_in_vector ( const T &  value,
const CONTAINER &  vect 
)

Returns the index of the value "T" in the container "vect" (std::vector,std::deque,etc), or string::npos if not found.

Definition at line 203 of file stl_extensions.h.

References mrpt::math::distance().

Referenced by mrpt::graphslam::optimize_graph_spa_levmarq(), and mrpt::bayes::CKalmanFilterCapable< 7, 3, 3, 7 >::runOneKalmanIteration().

◆ MRPTSTL_SERIALIZABLE_SEQ_CONTAINER()

mrpt::utils::MRPTSTL_SERIALIZABLE_SEQ_CONTAINER ( std::vector  )

Template method to serialize a STL pair.

Definition at line 132 of file stl_extensions.h.

References mrpt::utils::TTypeName< T >::get().

◆ nonConstBind1st()

template<typename Op >
NonConstBind1st<Op> mrpt::utils::metaprogramming::nonConstBind1st ( Op &  o,
typename Op::first_argument_type &  t 
)
inline

Use this function instead of directly calling NonConstBind1st.

Definition at line 363 of file metaprogramming.h.

References t().

◆ nonConstBind2nd()

template<typename Op >
NonConstBind2nd<Op> mrpt::utils::metaprogramming::nonConstBind2nd ( Op &  o,
typename Op::second_argument_type &  t 
)
inline

Do not directly use the NonConstBind2nd class directly.

Use this function.

Definition at line 382 of file metaprogramming.h.

References t().

◆ operator>>()

template<class T1 , class T2 >
CStream& mrpt::utils::operator>> ( CStream in,
std::pair< T1, T2 > &  obj 
)

Template method to deserialize a STL pair.

Definition at line 186 of file stl_extensions.h.

References mrpt::format(), mrpt::utils::TTypeName< T >::get(), and THROW_EXCEPTION.

◆ printf_vector()

template<typename T >
void mrpt::utils::printf_vector ( const char *  fmt,
const std::vector< T > &  V 
)

Prints a vector in the format [A,B,C,...] to std::cout, and the fmt string for each vector element.

Definition at line 269 of file stl_extensions.h.

References mrpt::utils::sprintf_vector().

◆ sprintf_vector() [1/2]

template<typename T >
std::string mrpt::utils::sprintf_vector ( const char *  fmt,
const std::vector< T > &  V 
)

Generates a string for a vector in the format [A,B,C,...] to std::cout, and the fmt string for each vector element.

Definition at line 240 of file stl_extensions.h.

References mrpt::format().

Referenced by mrpt::math::CLevenbergMarquardtTempl< VECTORTYPE, USERPARAM >::execute(), and mrpt::utils::printf_vector().

◆ sprintf_vector() [2/2]

template<typename Derived >
std::string mrpt::utils::sprintf_vector ( const char *  fmt,
const Eigen::MatrixBase< Derived > &  V 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 254 of file stl_extensions.h.

References mrpt::format().

◆ wrapMember() [1/3]

template<typename T , typename U1 , typename U2 , typename V >
BinaryMemberFunctionWrapper<T,U1,U2,V> mrpt::utils::metaprogramming::wrapMember ( V &  obj,
T(V::*)(U1, U2)  fun 
)
inline

This function creates a function from an object and a member function.

It has three overloads, for zero, one and two parameters in the function.

Definition at line 337 of file metaprogramming.h.

◆ wrapMember() [2/3]

template<typename T , typename U , typename V >
UnaryMemberFunctionWrapper<T,U,V> mrpt::utils::metaprogramming::wrapMember ( V &  obj,
T(V::*)(U)  fun 
)
inline

Definition at line 340 of file metaprogramming.h.

◆ wrapMember() [3/3]

template<typename T , typename V >
MemberFunctionWrapper<T,V> mrpt::utils::metaprogramming::wrapMember ( V &  obj,
T(V::*)(void)  fun 
)
inline

Definition at line 343 of file metaprogramming.h.




Page generated by Doxygen 1.8.14 for MRPT 1.0.2 SVN: at lun oct 28 00:52:41 CET 2019 Hosted on:
SourceForge.net Logo