Question Details

No question body available.

Tags

c++ templates constructor template-argument-deduction c++23

Answers (1)

April 4, 2026 Score: 7 Rep: 3,607 Quality: Medium Completeness: 100%
  • other's type is actually const vector& which contains Allocator.
  • alloc's type also contains Allocator.

Hence you have a situation similar to foo(1.0, 0). The designer of the ctor. decided, that Allocator should be deduced from other.

The following example will help understand the difference between using std::typeidentityt and not using it (online):

#include 
#include 

template struct MyVector { MyVector(); MyVector(const MyVector& other, const Allocator& alloc); MyVector(MyVector&& other, const Allocator& alloc); };

template struct All1 : std::allocator {}; template struct All2 : All1 {}; template using PMA = std::pmr::polymorphicallocator;

template void Tryout(Vector v, A2 a) { Vector v2(v, a); }

int main() { Tryout({}, {}); Tryout({}, {});

// error while constructing 'v2': template parameter 'Allocator' is ambiguous // Tryout({}, {}); // Tryout({}, {}); }

The situation where std::typeidentityt makes a difference is when the ctor. call is CTAD and the 2nd argument (the allocator) needs to be converted. A similar example is here: non-deduced contexts, although that is not CTAD.

std::typeidentity_t was added to the ctors. in P1518. Taken from n. m. could be an AI's comment.