I tried using arrays but I don’t need every single element, and so it won’t compile because my bounds are too large.
So, I want to try something more dynamic, perhaps using a map or a vector or something (whatever you guys recommend).
Like I have a function:
long long func(long long arg1, long long arg2, long long arg3){
check if [arg1, arg2, arg3] is memoized, and if it is, return it
....function body...
store return value with [arg1, arg2, arg3] in memoization cache
return value;
}
How can I do this?
You can use
mapto mappair<pair<long long, long long>, long long>tolong long.If you want to check whether the key is there or not, just use find(). Assigning and accessing key that you confirm exists in the map can be done safely with
[]overloaded operator.EDIT
Alternatively, you can define your own structure that contains the 3
long longkeys, and define their natural ordering (formapto work correctly). Then you can avoid the lengthypairsyntax.