mercredi 29 mars 2017

Wrapping container for containers providing other interface

I want to create universal "wrapper" for stl containers, something like:

template<template <typename, typename...> class Container = std::vector >
class ContainerWrapper{
  add();
  size();
  find();
  resize();
  sort(); 
  /**/
}

+iterators. I would want member functions to have different implementations, depending on Container provided methods. Is C++ template system enough to create this? Is this even possible, using only standard (no boost, no messing with preprocessor)?

I know how to do it the hard way - write template specialization for each stl container. But I would want it to work with other containers too, and also i'm looking for more universal way to do it.

Also, what is better here? Inheriting from Container or having Container as component?

Aucun commentaire:

Enregistrer un commentaire