Pass by value or by reference:
This will create a copy of string:
std::vector<std::string> mylib::split(std::string string, char delimiter)
This will pass a reference of string:
std::vector<std::string> mylib::split(std::string &string, char delimiter)
In the above cases, you would prefer to pass reference, because you return a std::vector and you only use string to read a part of it to push it to the vector. Now because you only read it, it would even be better to make it const:
std::vector<std::string> mylib::split(const std::string &string, char delimiter)
Then you are 100% sure that the variable you gave to the split function remains unchanged. Imagine the following:
std::string string = "some,values";
If you pass string to split by value:
std::vector<std::string> mylib::split(std::string string, char delimiter) {
string = "something else";
...
}
After calling split, you read the string variable:
std::cout << string << std::endl;
This will print "some,values".
If you pass by reference however:
std::vector<std::string> mylib::split(std::string &string, char delimiter) {
string = "something else";
}
It will print "something else", basically your modifying the real string.
If you make it const, then the compiler will not allow you to overwrite string in the split function. So unless your variable needs to be changed in the function, pass a const reference to it.
Moving or copying:
This will create a copy of string:
result.push_back(std::string(cache));
This will move the contents of cache.
result.push_back(std::move(cache));
If you know that creating a copy will usually cost more than moving things around, then you understand that moving will be more efficient, i.e. faster. But then again, adding move calls for a string sounds like premature optimization. Unless you are dealing with a lot of data, I don't see a reason to move a string instead of copying because it makes the code less readable and the performance gain would probably be minimal.
Pointers vs references
Basically you can think of a pointer like you think of a reference. It's an address to a piece of memory. The syntax is different, pointers can be null while references can't. Pointers can also be allocated on the heap while references are always allocated on the stack.
std::string string = "some,values";
std::vector<std::string> mylib::split(std::string *string, char delimiter) {
*string = "something else";
...
}
std::cout << *string << std::endl; // will print "something else"
std::cout << string << std::endl; // will print the address of the pointer
Notice the * in split is telling that you pass a pointer, the * before string '*string = "something else"' means that the pointer is dereferenced and that the value is written to the location of the pointer. Same for the print, we read the value and print it by dereferencing the pointer.
I hope that clears up some doubts you have.