Dear C++ people: how do you actually fucking do this? It seems bad enough that I need to have two overloads just to allow for the "no args" version.

But that template overload fails at link time because of an undefined symbol???

UPDATE: It鈥檚 because I needed to define it in the header file itself, not just declare it

@zkat
```cpp
#include <format>
#include <print>

template <typename... Args>
void info(std::format_string<Args...> fmt, Args&&... args) {
auto res = std::format(fmt, std::forward<Args&&>(args)...);
std::println("{}", res);
}

int main() {
info("{}", 42);
info("moi");
}
```

Seems to work in compiler explorer. Typos might be present, writing this on phone. Did you need something else?

Failing on link time might happen if you have template in a source code file not visible to an another translation unit (which is why we write template code into headers, or modules if we're in the future).

@lauren Typical. Still not the craziest thing he鈥檚 uttered.

Did not have cheering for Murdoch on my 2025 bingo card. #include nathanfillion.gif

alcinnz
BjarniBjarniBjarni  馃檴 馃嚠馃嚫 馃崗
alcinnz and 1 other boosted

This was fun - missing.c:

#include
#include

void die(int err, char *msg) {
err? fprintf(stderr, "%s\n", msg), exit(1): 0;
}

int main(int argc, char *argv[]) {
int n, answer = 1, val;

die(argc != 2 || (n = atoi(argv[1])) < 2, "Usage: missing n");
for (; n > 1; n--) {
die(scanf("%d", &val) != 1, "Error reading input");
answer ^= val ^ n;
}
printf("%d\n", answer);
}

This was fun - missing.c:

#include
#include

void die(int err, char *msg) {
err? fprintf(stderr, "%s\n", msg), exit(1): 0;
}

int main(int argc, char *argv[]) {
int n, answer = 1, val;

die(argc != 2 || (n = atoi(argv[1])) < 2, "Usage: missing n");
for (; n > 1; n--) {
die(scanf("%d", &val) != 1, "Error reading input");
answer ^= val ^ n;
}
printf("%d\n", answer);
}