I learned about std::forward_as_tuple
. I use this tech in my project:
template<class... Ts>
tuple<Ts&&...> values(Ts&&... ts) // yes, values is renamed forward_as_tupe
{
return tuple<Ts&&...>(std::forward<Ts>(ts)...)
}
class C_SQL { ...... }; // MySQL C API, SQL statement encapsulation
// operator% is well defined.
char pszname[32];
int iage;
C_SQL sql;
sql % "insert into student (name,age,grade)"
% values(pszname, iage, 2 );
Then, I can get a MySQL C API Prepared Statement string like this:
"insert into student (name,age,grade) values(?, ?, 2 )"
"pszname" and "iage" are lvalues, so they are binding variables. 2
is an rvalue, so I can tell that it's a literal in an SQL statement.
My question is:
How can I tell if an element in a tuple is an rvalue or an lvalue?
For example:
int k;
tuple<int&, int&&> t = forward_as_tuple(k, 2);
The first element is an lvalue-reference, the second is an rvalue-reference.
Please use C++ code to tell that. The code can deal with varaidic template tuple.