LINUX.ORG.RU

История изменений

Исправление quasimoto, (текущая версия) :

http://www.cplusplus.com/reference/stl тоже не умеют.

Такое чувство, что я единственнй кто это пробовал, ибо в гугле ничего похожего ненашел.

http://stackoverflow.com/q/2759350 и вообще google://any-standard-container+const.

Вот минимальный пример с которым T / const T работает:

template <typename T> // requires: T is regular (http://www.stepanovpapers.com/DeSt98.pdf) type.
struct singleton {
    typedef T value_type;
    T value;
    ~singleton() {}
    singleton() : value() {}
    singleton(singleton const& x) : value(x.value) {}
    explicit singleton(T const& value_) : value(value_) {}
    template <typename U> explicit singleton(singleton<U> const& x) : value(x.value) {}
    operator T() const { return value; }
    singleton& operator=(T const& value_) { value = value_; return *this; }
    singleton& operator=(singleton const& x) { value = x.value; return *this; }
    friend bool operator==(singleton const& x, singleton const& y) { return x.value == y.value; }
    friend bool operator!=(singleton const& x, singleton const& y) { return !(x == y); }
    friend bool operator<(singleton const& x, singleton const& y) { return x.value < y.value; }
    friend bool operator<=(singleton const& x, singleton const& y) { return !(y < x); }
    friend bool operator>(singleton const& x, singleton const& y) { return y < x; }
    friend bool operator>=(singleton const& x, singleton const& y) { return !(x < y); }
};

А если контейнер так не умеет — можно брать C<T> const вместо C<T const> — составить C<T> и передавать как C<T> const& по надобности.

Исправление quasimoto, :

http://www.cplusplus.com/reference/stl тоже не умеют.

Такое чувство, что я единственнй кто это пробовал, ибо в гугле ничего похожего ненашел.

http://stackoverflow.com/q/2759350 и вообще google://any-standard-container+const.

Вот минимальный пример с которым T / const T работает:

template <typename T> // requires: T is regular type.
struct singleton {
    typedef T value_type;
    T value;
    ~singleton() {}
    singleton() : value() {}
    singleton(singleton const& x) : value(x.value) {}
    explicit singleton(T const& value_) : value(value_) {}
    template <typename U> explicit singleton(singleton<U> const& x) : value(x.value) {}
    operator T() const { return value; }
    singleton& operator=(T const& value_) { value = value_; return *this; }
    singleton& operator=(singleton const& x) { value = x.value; return *this; }
    friend bool operator==(singleton const& x, singleton const& y) { return x.value == y.value; }
    friend bool operator!=(singleton const& x, singleton const& y) { return !(x == y); }
    friend bool operator<(singleton const& x, singleton const& y) { return x.value < y.value; }
    friend bool operator<=(singleton const& x, singleton const& y) { return !(y < x); }
    friend bool operator>(singleton const& x, singleton const& y) { return y < x; }
    friend bool operator>=(singleton const& x, singleton const& y) { return !(x < y); }
};

А если контейнер так не умеет — можно брать C<T> const вместо C<T const> — составить C<T> и передавать как C<T> const& по надобности.

Исходная версия quasimoto, :

http://www.cplusplus.com/reference/stl тоже не умеют.

Такое чувство, что я единственнй кто это пробовал, ибо в гугле ничего похожего ненашел.

http://stackoverflow.com/q/2759350 и вообще google://any-standard-container+const.

Вот минимальный пример с которым T / const T работает:

template <typename T> // requires: T is regular type.
struct singleton {
    typedef T value_type;
    T value;
    ~singleton() {}
    singleton() {}
    singleton(singleton const& x) : value(x.value) {}
    explicit singleton(T const& value_) : value(value_) {}
    template <typename U> explicit singleton(singleton<U> const& x) : value(x.value) {}
    operator T() const { return value; }
    singleton& operator=(T const& value_) { value = value_; return *this; }
    singleton& operator=(singleton const& x) { value = x.value; return *this; }
    friend bool operator==(singleton const& x, singleton const& y) { return x.value == y.value; }
    friend bool operator!=(singleton const& x, singleton const& y) { return !(x == y); }
    friend bool operator<(singleton const& x, singleton const& y) { return x.value < y.value; }
    friend bool operator<=(singleton const& x, singleton const& y) { return !(y < x); }
    friend bool operator>(singleton const& x, singleton const& y) { return y < x; }
    friend bool operator>=(singleton const& x, singleton const& y) { return !(x < y); }
};

А если контейнер так не умеет — можно брать C<T> const вместо C<T const> — составить C<T> и передавать как C<T> const& по надобности.