Skip to main content
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
4 votes
1 answer
159 views

Defaulting three way comparison operator in recursive data structures

I'd like to use a defaulted three-way comparison operator in a recursive data structure, like this: struct MyStruct { int i; std::vector<MyStruct> v; std::partial_ordering operator<=>...
user3188445's user avatar
  • 4,898
2 votes
1 answer
126 views

Clarification about user-provided explicitly-defaulted function being implicitly defined as deleted

As per the document, which says that (emphasis mine): A function is user-provided if it is user-declared and not explicitly defaulted or deleted on its first declaration. A user-provided explicitly-...
John's user avatar
  • 3,564
0 votes
1 answer
91 views

How to Check if a Constructor is Explicitly-Defaulted [closed]

For example: struct X { X(){/***/} X(const int& ){/***/} X( int&&){/***/} X(const X& ) = default; X( X&&) = default; X& operator=(const X&...
J L's user avatar
  • 655
8 votes
1 answer
141 views

Why can't most defaulted operators have a placeholder return type, i.e. auto?

C++20 has made it possible to default comparison operators, including the three-way comparison like this. <=> can have a deduced return type, but other operators can't: struct S { friend ...
Jan Schultke's user avatar
  • 43.3k
0 votes
0 answers
1k views

error: use of deleted function operator=(&&) with std::optional

I got myself an error sprouting from std::optional. Now when trying to reconstruct it, there seems to be something going on with defaulted ctors that I don't yet understand. Consider the following ...
glades's user avatar
  • 5,344
0 votes
1 answer
724 views

Declaration of operator has a different exception specifier

I am trying to "=default" my friend functions but keep getting the following error: a4.cpp:180:17: error: declaration of ‘bool operator==(const playing_card&, const playing_card&) ...
mariacat's user avatar
2 votes
1 answer
195 views

Why does a defaulted default constructor depend on whether it is declared inside or outside of class?

In the following example, struct A does not have default constructor. So both struct B and struct C inherited from it cannot get compiler-generated default constructor: struct A { A(int) {} }; ...
Fedor's user avatar
  • 24.1k
8 votes
1 answer
151 views

Can special member functions be defaulted if they use typedefs?

Clang compiles this fine, but GCC and MSVC complain that operator= cannot be defaulted: #include <type_traits> template<class T> struct S { typedef typename std::enable_if<!std::...
user541686's user avatar
  • 212k
5 votes
1 answer
2k views

Why C++20 allows defaulted comparison to compile even when it is deleted?

Consider the following code: struct A { }; struct B { A a; bool operator == (const B& other) const = default; }; clang gives a nice warning : warning: explicitly defaulted equality ...
NoSenseEtAl's user avatar
  • 30.9k
1 vote
2 answers
167 views

Why does copy-and-swap in a base class cause the copy-assignment operator to be implicitly deleted in the derived class?

Tested only in GCC and Clang, the presence of a pass-by-value copy assignment operator in the base class (useful when implementing the copy-and-swap (or copy-and-move) idiom) causes the copy ...
SumDood's user avatar
  • 304
1 vote
1 answer
527 views

C++ implicit definition of special functions

In the current version of the C++ draft (september 2019), paragraph [class.default.ctor]/4 states: A default constructor that is defaulted and not defined as deleted is implicitly defined when it is ...
user42768's user avatar
  • 1,981
7 votes
2 answers
394 views

Why is the constructor of std::in_place_t defaulted and explicit?

cppreference shows the following definition of std::in_place_t: struct in_place_t { explicit in_place_t() = default; }; inline constexpr std::in_place_t in_place{}; Why have they added an ...
Martin Fehrs's user avatar
  • 1,165
3 votes
3 answers
287 views

C++11 deleted/defaulted constructors

I'm a bit confused about how/why the constructors are called in C++11 and C++17. #include <iostream> using namespace std; //--- template<typename T> struct StructTest { public: const ...
Andy's user avatar
  • 137
1 vote
2 answers
1k views

What are the pros and cons of always declaring defaulted constructors?

What are the pro and cons of declaring always defaulted constructors for each non user-defined constructor? Consider a class with a user-defined constuctor which does not need other user-defined ...
Moia's user avatar
  • 2,394

15 30 50 per page