Skip to main content
1 vote
2 answers
156 views

Why can't this friend class access the private move constructor?

I get an error at the static assert: #include <type_traits> template <typename element_t> class MyVector { public: static_assert(std::is_move_constructible_v<element_t>); ...
Zebrafish's user avatar
  • 16.1k
3 votes
2 answers
204 views

What is the rationale behind the C++ compiler’s rules for implicitly declaring special member functions?

I came across this table describing how the C++ compiler implicitly declares special member functions depending on which ones the user has explicitly declared: Source: Howard Hinnant - How I Declare ...
toliveira's user avatar
  • 1,857
13 votes
1 answer
717 views

Is implicit conversion to std::optional guaranteed to use move constructor?

The following code block illustrates a difference between returning a std::optional via an implicit conversion (i.e. fn) vs. an explicit construction (i.e. fn2). Specifically, the implicit conversion ...
MarkB's user avatar
  • 2,210
6 votes
1 answer
199 views

Can move constructor with (const T&&) parameter be defaulted?

I see a similar question Default move constructor taking a const parameter, which is 8 years old, with the answer No. But at the same time, a slightly modified program with the constructor defaulted ...
Fedor's user avatar
  • 24.1k
0 votes
1 answer
109 views

Does the compiler generate the move operations (not default) in case of a default destructor? [duplicate]

A relatively same question is asked before, but the code snippet is different, which I believe makes this question unique. Does the compiler generate the move operations in the following scenario? ...
Ali Sedighi's user avatar
1 vote
1 answer
89 views

`auto x = nonmoveable{};` rejected by MSVC but allowed by GCC and clang

I am trying to move from T t{ ... }; construction to auto t = T{ ... }; in order to make it consistent with function calls like auto p = std::make_unique<T>(...);. I am however running into ...
Dominik Kaszewski's user avatar
3 votes
0 answers
81 views

C++: Constructor invocation when initializing from a function returning a reference to *this

I'm trying to understand the exact behavior of object initialization in C++ when using a function that returns a reference to *this. Consider the following generic code: class T { public: T& ...
michael3.14's user avatar
2 votes
1 answer
91 views

Why does moving a const ref return value into another function still move-construct the object?

In the following example the function Table::get_subtable() is returning a const reference to an internal subobject (SubTable). This value is then std::moved and passed into a static factory function ...
glades's user avatar
  • 5,344
0 votes
1 answer
85 views

std::string and default move constructor causing heap corruption

While refactoring some code, I've run into an issue with heap corruption. namespace GPU { struct ShaderStage { public: ShaderStage(ShaderStageType, const Path&); ...
garlfin's user avatar
  • 11
1 vote
1 answer
137 views

Why is the move constructor is not being called?

Below is my C++ code. I was expecting my move ctor to be called here in my main: Mystring larry2 = "some larry"; main.cpp: int main() { //Mystring no_name; Mystring larry ("...
gaurav s's user avatar
4 votes
0 answers
166 views

move or copy -- major compilers disagree, who's right?

A class below is a wrapper that either keeps a reference on lvalue or a copy of rvalue. The latter is either copied or moved depending on specialization. This is a very common problem when using ...
Gene's user avatar
  • 754
2 votes
2 answers
169 views

GCC does not generate machine code for out-of-class defaulted copy constructor

Assume the following source file (translation unit; TU): struct X { int i; X(const X&); X(X&&); }; X::X(const X&) = default; X::X(X&&) = default If I compile ...
Daniel Langr's user avatar
  • 23.9k
3 votes
2 answers
213 views

Is there any type defined in Standard Library which has copy constructor but doesn't have a move constructor?

In general, the C++ Standard Library types are designed with both copy and move semantics in mind. Is there any type defined in the Standard Library which has a copy constructor but doesn't have a ...
John's user avatar
  • 3,564
0 votes
3 answers
173 views

Returning an object with only explicit move constructor

The following code would not compile: #include <utility> class Foo{ public: Foo(const Foo& foo) = delete; explicit Foo(Foo&& foo) = default; Foo() = default; Foo ...
ttzytt's user avatar
  • 101
0 votes
0 answers
42 views

How to use only the move constructor and the move assignment operator [duplicate]

Please tell me how I can correct this piece of code so that the cookie_name_t class does not use a copy constructor and an assignment constructor. When I do the following: cookie_name(cookie_name ...
Tippa Toppa's user avatar

15 30 50 per page
1
2 3 4 5
30