Skip to main content
1 vote
0 answers
68 views

I encountered a situation when a newly created const-qualified std::valarray<size_t> is passed to another std::valarray’s subscript operator [] when defining a std::indirect_array. This worked ...
Peter's user avatar
  • 113
5 votes
2 answers
242 views

In the following simplified program, I try to create a std::vector object sized according to an enumerator value: #include <vector> enum class E { Count }; int main() { std::vector<int*&...
Fedor's user avatar
  • 24.7k
5 votes
1 answer
191 views

I have two classes st and foo: struct st { st() = default; st(const st&) { std::cout << "copy ctor." << std::endl; } st(st&&) { std::...
ValueError's user avatar
2 votes
1 answer
84 views

Why is this an illegal declaration? > std::views::iota r(0, 10); error: expected ‘;’ before ‘r’ but this works > auto r = std::views::iota(0, 10);
Cherif's user avatar
  • 85
3 votes
1 answer
78 views

It is well known that for a class with deleted copy and move constructors, it is still possible to direct initialize an object from a prvalue such as the return value of a function. For example, this ...
Ari's user avatar
  • 33
2 votes
1 answer
118 views

I'm aware that uniform initialization using braced-init list don't allow narrow conversion (ex double -> int) but member initialization using init list allows narrow conversion. struct Mem1 { ...
ssh's user avatar
  • 79
20 votes
1 answer
878 views

I have the following code: #include <iostream> #include <vector> struct C { int a; C() : a(0) {} C(int a) : a(a) {} }; std::ostream &operator<<(std::ostream &os, ...
Matvei's user avatar
  • 217
0 votes
0 answers
73 views

In some Boost ASIO example, I found the line auto self(shared_from_this());. self doesn't seem to be declared anywhere and doesn't seem to be a reserved keyword. In another example, I also found the ...
medihack's user avatar
  • 16.7k
0 votes
1 answer
77 views

Assume I have this code T object(other); It is direct initialization or copy initialization? Based on the rule of direct initialization : T object ( arg ); initialization with a nonempty ...
Kevin eyeson's user avatar
2 votes
1 answer
142 views

I always thought direct initialization and copy initialization for types T that do not match the class type are absolutely equal. Yet I seem to be mistaken. The following code doesn't compile if I ...
glades's user avatar
  • 5,374
0 votes
1 answer
523 views

When I'm trying to compile the following code, the compiler complains: int main(void) { std::initializer_list<int> lst1{}; std::initializer_list<int> lst2{lst1}; // error } The ...
mada's user avatar
  • 2,033
5 votes
2 answers
126 views

Consider the following code: struct S { S(int, double) {} explicit S(const S&) {} explicit S(S&&) {} }; void i_take_an_S(S s) {} S i_return_an_S() { return S{ 4, 2.0 }; } ...
Ruperrrt's user avatar
  • 549
1 vote
2 answers
159 views

Consider a case where we've reached into bullet [dcl.init.ref]/(5.4.1) during reference binding: (5.4.1) If T1 or T2 is a class type and T1 is not reference-related to T2, user-defined conversions ...
mada's user avatar
  • 2,033
4 votes
1 answer
239 views

In the following program the object A a is directly initialized from braced-init-list {A{}}: #include <iostream> struct A { int v = 0; A() {} A(const A &) : v(1) {} }; int main(...
Fedor's user avatar
  • 24.7k
2 votes
1 answer
376 views

I have the following example: struct S{ int x, y; } S s1{1}; // direct-initialization or direct-list-initialization ? S s2{1, 2}; // direct-initialization or direct-list-initialization ? S s3(1)...
mada's user avatar
  • 2,033

15 30 50 per page