"Ola Fosheim "Grøstad\"" <ola.fosheim.grostad+dl...@gmail.com> writes:
> On Monday, 1 June 2015 at 16:09:34 UTC, Dan Olson wrote: >> Timely! I and stack overflow struggled for a couple hours to find >> an >> equivalent C++ template for something that was straightforward with >> a >> couple macros. > > …but without an example it is hard to figure out what macros are > needed for. Stringify - here I want to rapidly prototype code with syscalls that need return values checked, and get nice output when they fails. My C++ template skills are weak and was unable to come up with an equivalent replacement. Is this a way? #define STRINGIFY(x) #x #define STR(x) STRINGIFY(x) #define SYSCHK(syscall) \ ({__typeof__(syscall) r = (syscall); \ if (r == -1) die(__FILE__ ":" STR(__LINE__) ":" #syscall " failed"); \ r;}) int fd = SYSCHK(open(fname, O_EVTONLY)); int kfd = SYSCHK(kqueue()); struct kevent changes; ... struct kevent kevs[5]; int n = SYSCHK(kevent(kfd, &changes, 1, kevs, 5, 0));