I\'ve been experimenting with std::tuple in combination with references:
#include
#include
int main() {
int a,
std::tie makes non-const references.
auto ref_tuple = std::tie(a,b); // decltype(ref_tuple) == std::tuple
For const references, you'll either want the std::cref wrapper function:
auto cref_tuple = std::make_tuple(std::cref(a), std::cref(b));
Or use a simply as_const helper to qualify the variables before passing them off to std::tie:
template
T const& as_const(T& v){ return v; }
auto cref_tuple = std::tie(as_const(a), as_const(b));
Or, if you want to get fancy, write your own ctie (reusing std::tie and as_const):
template
std::tuple ctie(Ts&... vs){
return std::tie(as_const(vs)...);
}
auto cref_tuple = ctie(a, b);