174 questions
3 votes
1 answer
223 views
Why is `""s.size()` legal, but `5ms.count()` is not? [duplicate]
#include <chrono> #include <string> using namespace std::literals; int main() { ""s.size(); // ok (""s).size(); // ok (5ms).count(); // ok 5ms....
1 vote
2 answers
82 views
gcc/clang unresolved user-defined literal template operator""
I'm trying to parse UUID expression using C++23, However compiling under clang 20.1.6 and gcc 15.1.0 find the operator as candidates yet it get ignored. here is my code: union uuid_t { unsigned ...
1 vote
1 answer
117 views
Why does the friend template function have different behaviors for struct and class?
#include <array> template<std::size_t tc_n> requires (tc_n > 0) struct StringLiteral final { std::array<char, tc_n> value{}; consteval StringLiteral(char const (&sl)[...
5 votes
1 answer
62 views
Qualify invocation of ambiguous UDL
I have two namespaces which both define the same User Defined Literals: namespace foo { struct x{ unsigned long long i; }; namespace literals { constexpr foo::x operator""_x(...
-2 votes
1 answer
72 views
clang c++ friend user defined literal declare failed [duplicate]
namespace ns { class MyClass { private: int value; MyClass(int val) : value(val) {} friend MyClass operator"" _myudl(unsigned long long int val); // Friend UDL declaration ...
0 votes
0 answers
168 views
Portable macro that declares parametrized user define literal
I want to define a preprocessor macro with parameter N that constructs a declaration for C++ user-defined literal with suffix _uN. #define DEFINE_LITERAL(N) int operator""_u##N(const char* s)...
3 votes
2 answers
247 views
How to avoid duplication of string literal text in functions that accept different width characters / strings?
I frequently need to create string manipulation functions in C++. My APIs tend to be written to accept std::basic_string<T> (effectively), but I also want to accept std::basic_string_view<T&...
9 votes
1 answer
473 views
Clang rejects std::array initialisation but gcc accepts
I am learning about user defined literals and I wrote the following program that works with gcc and msvc but clang rejects it. Live demo #include <array> template<std::size_t N> struct ...
0 votes
0 answers
100 views
Why do user defined literal operators have to start with underscore?
Since the Standard Library never defines literal operators in the root std namespace, what is the danger of having user defined operators not starting with underscore?
3 votes
1 answer
463 views
C++ user-defined string literal template weird issue (getting string literal length as compile-time constant)
I'm trying to define a user-defined string literal template. Shouldn't that code snippet work? / Why doesn't it work? template<char...> constexpr int operator ""_x () { return 0; } ...
7 votes
2 answers
405 views
Do preprocessor defines substitute in `operator""_name`
Consider the following example provided by Aykhan Hagverdili: #include <string> using std::operator""s; #define s foobar auto s = "hello world"s; Some compilers would ...
0 votes
1 answer
53 views
Why the move constructor nor the move assign operator is not called in this expression with UDL?
I have a class with copy constructor and copy assign operator deleted. Move constructor amd move-assign operator are present. It also defines an operator<<: struct S { S(std::size_t s) {} ...
5 votes
2 answers
811 views
Should user defined literals always be consteval in C++20?
If I'm not mistaken, the arguments for a user defined literal are always known at compile time. In C++20 you can force functions to execute at compile time using consteval so that throw generates a ...
1 vote
2 answers
147 views
Literals don't work for preprocessor macros
Literals don't seem to interplay well with preprocessor macros. For example, I have this preprocessor definition CONFIG_FADE_DELAY_MS that I want to translate to std::chrono::milliseconds. But the ms ...
1 vote
1 answer
275 views
What is wrong with operator"" _Bq?
At [over.literal] I read, in the list of examples, that double operator""_Bq(long double); is valid, whereas double operator"" _Bq(long double); is ill-formed, which is ...