jeudi 10 août 2017

How to use std::move() to move char[] to a vector

I am trying to concatenate two char arraies char a[9000]; char b[9000] to a container std::vector. Since the array size is not small. I am trying to use std::move()

class obj
{
public:
obj &operator <<(char *&&ptr)
        {
            //???
            ptr = nullptr;
            return *this;
        }
private:
    std::vector<char> m_obj;
};

So in the main function

int main()
{
    obj o;
    enum {SIZE=9000};
    char a[SIZE]; memset(a, 1, SIZE);
    char b[SIZE]; memset(b, 2, SIZE);
    o << a << b;
    return 0;
}

My question is what is the correct way to move a char*?


Environment:
Ubuntu 16.04.4 LTS
g++ 5.4.0


Thanks,

Rong

Aucun commentaire:

Enregistrer un commentaire