4 ms·
They did link an hour long conference talk (which I haven't watched), that I assume explains in more detail the kind of logging system that they're working with
by senkora 3y ago
They did link an hour long conference talk (which I haven't watched), that I assume explains in more detail the kind of logging system that they're working with: https://www.youtube.com/watch?v=Dt0vx-7e_B0 https://www.youtube.com/watch?v=Dt0vx-7e_B0
I think that basically they want a class template magic_functor that can be invoked as below
magic_functor<std::source_location::file_name()>::type
And then they could get a compile-time number corresponding to the file_name by doing:
using T = magic_functor<std::source_location::file_name()>::type;
int x = my_logging_lib_string_to_number<T>();
But unfortunately it simply doesn't work, because magic_functor is unwritable, because a `const char *` doesn't remember its size like a `const char[]` does.
- ynik 3y agoIf the `const char*` is a compile-time value, you can get its size via `std::char_traits<char>::length()`. Here I could get `magic_functor<std::source_location::file_name()>::type` to work on MSVC: https://godbolt.org/z/Ph8dd78fa https://godbolt.org/z/Ph8dd78fa gcc doesn't accept this code, but that seems more like an implementation problem than a specification problem?
- gpderetta 3y agoThere are a lot of restrictions on what a pointer-type template parameter can point to. In particular it needs to have linkage (which for example string literals do not have). Whether the results of constexpr functions must, can or can't have linkage is beyond my paygrade, but I suspect this is an MSVC extension. edit: linkage appears to propagate through constexpr. So it depends on how ultimately the original string is generated. I don't know what guarantee the standard gives (cppreference doesn't mention anything and I can't be bothered to look at the standard).
- jeffreygoesto 3y agoI liked this better, it uses some macros but it's easily readable and compresses the logs nicely. https://youtu.be/FyJI4Z6jD4w https://youtu.be/FyJI4Z6jD4w