vendredi 24 avril 2015

C++ template constructor with iterators how to write when accepting items of different size

this is more a question of elegance than programming:

I have a DataContainer which holds an array of bytes (uint8), but I have different ctors which can take arrays of [uint8_t] and [uint16_t, uint32_t, uint64_t] ; packing by default to big-endian meaning:

DataContainer(
   const uint32_t * membytes, 
   std::size_t length,
   Packing option = BigEndian
);

then, now I would like to have an iterator interface to it, to handle strings and vectors in an elegant way ...; the problem is how to write it to make it obvious ; instead of grabbing the size of the item blindly (it::value_type), I thought about:

 dt<type>(beg, end) 

and template specializations but still not satisfied ; it doesn't look steady:

template <typename Iter>
        DataContainer(Iter beg, Iter end, ...) { ... }

then do you have some tips to share?, thank you for reading me.

Aucun commentaire:

Enregistrer un commentaire