4

I've got the following code:

template<typename... Args> constexpr static const inline int sc(Args&&... args)
{
    return scanf(_hidden::fmt< decltype(args+0)... >::result::data,
                 _hidden::link<decltype(&args),decltype(args+0)>({&args,args}).data...);
}

At least g++ compiler without -O3 flag compiles it to function call, ignoring inline parameter. How could I replace such complicated variadic expansion with macro or anything else, what would compile to single scanf call without extra functions using any compiler set? Just academic interest, in real cases -O3 flag does everything

Denis Sheremet
  • 2,453
  • 2
  • 18
  • 34
  • Have you tried link-time optimizations like `-flto` and `-fwhole-program`? Also, can you tell us what the second parameter is supposed to do? – edmz Nov 01 '15 at 10:01
  • Why? I/O will dominate your function call many times over. – n. m. could be an AI Nov 01 '15 at 11:01
  • @black , the question is not about compiler options, but about other ways of implementation. As I mentioned, I've already could compile it with -O3 and there will be no extra function call. Second and other arguments are the selectors between &args and args depending on type. `sc(i,s)` works as `scanf("%i%s",&i,s)`, for example. – Denis Sheremet Nov 01 '15 at 11:48
  • @n.m. , for academic interest, I just want to get better understanding of variadic macros and functions to make a better code in future – Denis Sheremet Nov 01 '15 at 11:57
  • 1
    Sorry I missed your last statement. I get your interest, but do notice that macros will not make your code any better, just worse. – edmz Nov 01 '15 at 12:05
  • When did scanf become constexpr? In the land of undefined behaviour, it is legal for the compiler to make demons fly out of your nose. – Rich L Jun 07 '18 at 10:37

0 Answers0