I have this code:
...
#include "boost/tuple/tuple_comparison.hpp"
...
template <typename ReturnType, typename... Args>
function<ReturnType(Args...)> memoize(const Args && ... args)
{
using noRef = boost::tuple<typename std::remove_reference<Args>::type...>;
static map<noRef, ReturnType, less<>> cache;
auto key = std::tie(noRef{ boost::make_tuple(args ...) });
auto it = cache.lower_bound(key);
ReturnType result;
if (it->first == key) { ...
But when I try to compile it I receive this error:
error C2678: binary '==': no operator found which takes a left-hand operand of type 'const noRef' (or there is no acceptable conversion)
Why this happens, since noRef
is an alias for boost::tuple
and tuple_comparison
should manage this case?
ERROR FOUND, DON'T KNOW HOW TO SOLVE IT:
It seems that the error was in the std::tie
operation. So rewriting it as:
auto key = noRef{ boost::make_tuple(args ...) };
Works fine. The problem is that this solution is inefficient, since key
is a potentially expensive copy of the whole tuple, while using tie
is a tuple of references (much smaller). So, how can I take a reference to it->first
tuple? Should I use the same tie
trick?