I have found a lot of examples from stack overflow, but those examples are based on non-const std::string. What if the string is const(top level and non top level)?
std::string encrypt(std::string const &input)
{
//do something, ArrayGuard is a smart pointer to guard the raw char* delete by free
ArrayGuard<char> guard(encrypt_str(const_cast<char*>(input.c_str())));
return std::string(guard.get(), std::strlen(guard.get()));
}
case 1(non top level?) :
std::string input = "abcde";
std::string encrypt_password = encrypt(input);
case 2(top level?) :
std::string const input = "abcde";
std::string encrypt_password = encrypt(input);
I am sure that the encrypt_str would not alter the char* I pass into it(if it is possible, I would like to ask them to fix this non const correction api).
ps : I am not sure that I am fully understanding what is top level const/&/&&/volatile, that is why I put "?" behind the case