sanjaykhan (4) [Avatar] Offline
In listing 6.7 ("Function that creates a memoized wrapper from a function pointer"), should the cache variable be static?
Ivan Cukic (80) [Avatar] Offline
No. The lifetime of the cache is tied to the lifetime of the lazy variable.

There are a few solutions that use a static cache, which I'll provide links to, but it is not something that this implementation needs.
Jan (1) [Avatar] Offline
Suppose I have the implementation of an expensive free function used all over my code in some source file.
How can I use make_memoized without changes outside of said source file?
My naive implementations give me a std::bad_alloc.
Ivan Cukic (80) [Avatar] Offline

If you had to preserve the API/ABI, you'd can create a static variable and a std::once_flag inside the function and use std::call_once to initialize said variable.

If this does not work for you, can you post the code you have the problem with?