Skip to main content
The 2026 Annual Developer Survey is live— take the Survey today!
Filter by
Sorted by
Tagged with
Filter by Employee ID
Score of 10
1 answer
599 views

If a lambda is capture-less, its closure type has conversion operator to function pointer. For example, auto l = []{}; using F = decltype(+l); //pointer to function type constexpr F p = l; And if a ...
Score of 2
1 answer
172 views

The following not very long program is treated differently by the current compilers: class A { protected: operator auto(); }; template<class> struct B : A { using A::operator auto; }; ...
Score of 5
0 answers
105 views

If you have something like this, struct Foo { }; constexpr auto pred = [](){ return Foo{}; }; calling std::not_fn(pred) will fail to compile, expectedly. However, adding an explicit conversion ...
Score of 5
1 answer
213 views

I have two classes st and foo: struct st { st() = default; st(const st&) { std::cout << "copy ctor." << std::endl; } st(st&&) { std::...
Score of 1
0 answers
48 views

I prefer to separate template declarations and definitions in headers and compilation units, and use template specific instantiation. But in this example, I cannot get the bool conversion operator ...
Score of 5
0 answers
260 views

In C++20 there is a rule that informally known as "when returning a variable, first try to move, and only then copy". More formally it is [class.copy.elision]/3 An implicitly movable entity ...
Score of 18
1 answer
725 views

I was playing with the following code. #include <iostream> struct To { To() = default; To(const struct From&) {std::cout << "Constructor called\n";} To(const To&...
Score of 1
2 answers
109 views

Take a simple class wrapping an int, struct Foo { int x; } f; and a class that holds a Foo and that can be converted to it, struct Bar { Foo f; operator Foo&() { return f; ...
Score of 8
1 answer
300 views

Assume we have procedure void f(X2);. Further assume we have types X1 and X2 that do not share an inheritance hierarchy. We want to call it like this: f(X1{}) and have X1 implicitly convert into X2. ...
Score of 1
1 answer
552 views

While answering another question, I noticed something peculiar about conversion operators when dealing with ref-qualifiers. Consider the following code: using P = std::unique_ptr<int>; struct A ...
Score of 5
1 answer
1150 views

I have several functions for a class which do the exact same thing but with a different type. class ExampleWrapper { public: operator T1() { ... } operator T2() { ... } operator T3() { ... ...
Score of 9
1 answer
220 views

In the following program struct B defines two conversion operators: to A and to const A&. Then A-object is created from B-object: struct A {}; struct B { A a; B() = default; operator const ...
Score of 7
1 answer
259 views

In the following program struct S provides two conversion operators: in double and in long long int. Then an object of type S is passed to a function f, overloaded for float and double: struct S { ...
Score of 3
1 answer
244 views

I have this class SmallInt that should represent a positive integer value in the range 0-255-inclusive: struct SmallInt{ explicit SmallInt(int x = 0) : iVal_( !(x < 0 || x > 255) ? x : ...
Score of 0
1 answer
205 views

I am trying to write a basic std::any alternative to use in my code, the reason is that i want to replace the templated std::any_cast with a conversion operator. the use case is to add some ...

15 30 50 per page
1
2 3 4 5
10