rttr::array_mapper< T > Struct Template Reference
The array_mapper class is a class template to access different array types via one common interface. More...
#include <array_mapper.h>
Public Types | |
using | array_type = T |
using | raw_type = typename array_mapper< T >::raw_type |
using | sub_type = T |
Static Public Member Functions | |
static std::size_t | get_size (const array_type &) |
static const T & | get_value (const array_type &arr, std::size_t index) |
static T & | get_value (array_type &arr, std::size_t index) |
static bool | insert_value (array_type &, const T &value, std::size_t,) |
static bool | is_dynamic () |
static bool | remove_value (array_type &, std::size_t) |
static bool | set_size (array_type &arr, std::size_t new_size) |
Detailed Description
template<typename T>
struct rttr::array_mapper< T >
The array_mapper class is a class template to access different array types via one common interface.
This class will be only used internally by RTTR via the variant_array_view class to get access to elements of an array. In order to use your own custom array type, you have to provide a specialization of this class.
Out of the box, RTTR has specialization for following array types:
, raw arraysT
[N]std::vector<T>
std::array<T
, N>std::list<T>
Custom array types
For a specialization of the class array_mapper<T> you have to provide two nested alias templates:
using raw_type = typename array_mapper<T>::raw_type;
using sub_type = T;
and following member functions:
static bool is_dynamic();
static bool set_size(array_type& arr, std::size_t new_size);
static const T& get_value(const array_type& arr, std::size_t index);
static T& get_value(array_type& arr, std::size_t index);
static bool insert_value(array_type& arr, const T& value, std::size_t index);
static bool remove_value(array_type& arr, std::size_t index);
Following code example for std::vector<T>
illustrates how to add a specialization:
namespace rttr
{
template <typename T>
struct array_mapper<std::vector<T> >
{
using sub_type = T;
{
return true;
}
{
return arr.size();
}
{
arr.resize(new_size);
return true;
}
{
return arr[index];
}
static T& get_value(std::vector<T>& arr, std::size_t index)
{
return arr[index];
}
{
arr.insert(arr.begin() + index, value);
return true;
}
{
arr.erase(arr.begin() + index);
return true;
}
};
} // end namespace rttr
- Remarks
- Make sure you put your specialization inside the namespace
rttr
. The best place for this code, is below the declaration of your custom array type. When this is not possible, include your specialization code before registering your types to RTTR.
Member Typedef Documentation
template<typename T>
using rttr::array_mapper< T >::array_type = T |
template<typename T>
using rttr::array_mapper< T >::raw_type = typename array_mapper<T>::raw_type |
template<typename T>
using rttr::array_mapper< T >::sub_type = T |
Member Function Documentation
template<typename T>
|
inlinestatic |
template<typename T>
|
inlinestatic |
template<typename T>
|
inlinestatic |
template<typename T>
|
inlinestatic |
template<typename T>
|
inlinestatic |
template<typename T>
|
inlinestatic |
template<typename T>
|
inlinestatic |
The documentation for this struct was generated from the following file: