C++ Class Templates

  • + 1 comment

    Move to C++20 and force std::cin with

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
    
    template <class T> class AddElements {
        T data;
    public:
        AddElements(T value) : data(value) {}
    
        T add(T a) {
            data += a;
            return data;
        }
    };
    
    template <> class AddElements<string> {
    public:
        string s;
    
        AddElements(const string& value): s(value) {}
        AddElements(string&& value): s(std::move(value)) {}
    
        string concatenate(const string& a) {
            return s.append(a);
        }
    };