Ok so I am writing a DB wrapper in c++0x, the API is in C.
I have preprepared statements which I can bind at runtime.
I would like to bind and execute the statement in 1 function call to the wrapper.
My initial though is to use variation templates. but with the documentation I have seen I have not found out how to limit the types that are entered as template types to fixed set (int, string, double), and how to be able to do basic logic on those types.
something like (pseudo code)
foreach arg in args
if arg1==std::string
bindToString(arg);
else if int...
thanks
Take advantage of function overloading.
void bind(std::string& arg) { bindstring(arg); }
void bind(int& arg) { bindint(arg); }
...
std::vector<boost::variant<double,std::string,int>> args = {...}
for (auto arg : args)
bind(arg);
-- edit --
Another approach using variadic template
void bind(std::string& arg) { bindstring(arg); }
void bind(int& arg) { bindint(arg); }
void bind(void) {}
template <typename T, typename... Args>
void bind(T& arg, Args& args)
{
bind(arg); bind(args...);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With