Reimplement boost::tuples::element and boost::tuples::get to make better use of memoization. Fixes #2130