次のように stl タプルを使用して、いくつかの変数の保存/復元機能を実装しています。
double a = 1, b = 2;
int c = 3;
auto tupleRef = std::make_tuple(std::ref(a), std::ref(b), std::ref(c));
// here I'm saving current state of a, b, c
std::tuple<double, double, int> saved = tupleRef;
//here goes block of code, where a, b, and c get spoiled
......................
//
//now I'm restoring initial state of a, b, c
tupleRef = savedTuple;
このコードはうまく機能します。ただし、明示的にタプル メンバー タイプを指定する代わりに、
std::tuple<double, double, int> saved = tupleRef;
次のように、すべての tupleRef メンバーから参照を削除したいと思います。
auto saved = remove_ref_from_tuple_members(tupleRef);
そのために「remove_ref_from_tuple_members」テンプレートを書くことは可能だと思います。
回答ありがとうございます。