vendredi 4 décembre 2015

Const reference wrapper from reference wrapper

Consider the following reference wrapper:

template <class T>
struct wrapper
{
    wrapper(T& x): reference{x} {}
    void set(const T& x) {reference = x;}
    T& get() const {return reference;}
    T& reference;
};

I am wondering:

  • How to declare a const reference wrapper through a template alias only template <class T> using const_wrapper = /* const wrapper<T> or wrapper<const T>?*/
  • How to change the wrapper struct to make the preceding point possible if it is not possible in this state?
  • How to solve the following problem: int i = 42; wrapper<const char> w(i); will compile but not work (I would like to block the constructor)
  • For what exact problem, iterator and const_iterator general have two different implementations?

Aucun commentaire:

Enregistrer un commentaire