samedi 4 avril 2015

How to store a structure of data in a template way?


Vote count:

0




I have a templated structure in which I want to pass as a template arguments 2 reference to functions - allocator and deallocator. Is there any way I can group them in a template-like structure so there won't be a chance for them to be mismatched?


I don't want to use a normal reference to structure because then there will be a lot different instances but I want one for each pair of functions.


Example:



template<bool bNoExcept>
struct type_object_factory_memory_mng_funcs
{
void *(&refAllocFunction)(std::size_t) noexcept(bNoExcept);

std::conditional<bNoExcept, bool, void> (&refDeAllocFunction)(void *) noexcept(bNoExcept);
};

template<typename Type, bool bNoExcept, type_object_factory_memory_mng_funcs<bNoExcept> &&refMemFuncs>
struct type_object_factory ; //here instance for each rvalue object passed will be created


Is there a better way?


I don't want to use this:



template<typename Type, bool bNoExcept, void *(&refAllocFunction)(std::size_t) noexcept(bNoExcept), std::conditional<bNoExcept, bool, void> (&refDeAllocFunction)(void *) noexcept(bNoExcept)>
struct type_object_factory ;


Becaus this way there is a big chance that not-matching functions will be passed. Any ideas how to overcome this?


I would also like to have a specific type for exception implicitly defined for each pair of functions that could throw.



asked 52 secs ago







How to store a structure of data in a template way?

Aucun commentaire:

Enregistrer un commentaire