Skip to content

Add user-defined literal to create a nametag provider from a string literal#107

Open
vaijns wants to merge 1 commit intorbock:mainfrom
vaijns:reflection-alias-udl
Open

Add user-defined literal to create a nametag provider from a string literal#107
vaijns wants to merge 1 commit intorbock:mainfrom
vaijns:reflection-alias-udl

Conversation

@vaijns
Copy link
Contributor

@vaijns vaijns commented Mar 17, 2026

Didn't realize this was possible just until I recently saw something similar done in a C++ standard paper. This would allow the reflection aliases to not use the template parameter overload but just pass the result of a user-defined literal as a normal parameter (because it creates a NameTagProvider directly). You can see an example in the tests or in the docs.

I don't have any preference, I'm fine with template parameters and just thought it's interesting. So only merge it if you'd prefer to have it, I'd be totally okay with the PR just being closed.

…iteral, usable as normal parameter to .as(<NameTagProvider>)
@rbock
Copy link
Owner

rbock commented Mar 18, 2026

That's super interesting! Can you provide the link to the paper you found the idea in?

@vaijns
Copy link
Contributor Author

vaijns commented Mar 18, 2026

That's super interesting! Can you provide the link to the paper you found the idea in?

I actually can't as I was wrong with that memory, it wasn't in a paper where I saw it. It was another project on github. Here I found the "string_literal"_c UDL in the README quite interesting. Then I saw the implementation for this UDL is just taking the StringLiteral as non-type template parameter, as I already knew was allowed for UDLs. But then I didn't realize with having it as non-type template parameter, I could just wrap it in another class to pass it around as a constant.

However, there are papers with similar concepts, though I didn't know about some of them before.

  • For one there was P2725 - std::integral_constant Literals which is pretty much the same, just for integral values.
  • Then - and this one is actually adopted and part of C++26 - there is P2781 - std::constant_wrapper. Which could be used as result type of something like operator""_c and passed around as "normal" parameter.
  • The last paper is P3094 - std::basic_fixed_string which mentions the possibility of user-defined literals. And I'm not quite sure, it could be those UDLs would've just returned a std::basic_fixed_string<CharT, N> instead of something like std::constant_wrapper<std::basic_fixed_string<CharT, N>{"my_string"}>, then it wouldn't have many similarities, in the latter case though it'd be pretty much the same.

Though instead of a more generic type like std::constant_wrapper<std::basic_fixed_string<CharT, N>{"my_string"}> and such, in this PR I just return the already existing sqlpp::meta::reflection_alias<Alias> directly. But I probably could've built this from a constant_wrapper too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants