Skip to content

Instantly share code, notes, and snippets.



Created Oct 9, 2016
What would you like to do?
#include <numeric>
template <typename T>
bool parse(const char* fromstr, T& dest) //T* still can be const T*, since cv is preserved
//parse and return 1 if succeeded
dest = T();
return 1;
template<typename T>
int parser(char const*& format, char const* input, T& value)
#if 0
if (/*T doesn't match the format*/)
throw bad_format_t{};
return parse(input, value); //<- tries to write into const object
template<typename... Args>
int tscanf(char const* format, char const* value, Args&... args)
auto count = {parser(format, value, args)...}; //<- lvalue refs again, cv preserved
return std::accumulate(std::begin(count), std::end(count), 0);
int main()
int test = 5;
int const test2 = 4;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment