Page 1 of 1

"Kopieren Sie Konstrukt" aus dem Behälter mit potenziell anderem Allocator

Posted: 05 Apr 2025, 09:09
by Anonymous
Bedenken Sie: < /p>

Code: Select all

template 
class Container
{
template 
Container(const Container &other)
: alloc(std::allocator_traits::select_on_container_copy_construction(other.alloc))
{
}

template 
Container(const Container &other)
: alloc(???)
{
}

private:
Alloc alloc;
};
Die Verwendung von std :: allocator_traits :: select_on_container_copy_construction ist im Kopienkonstruktor sofort offensichtlich [1, 2]. Spec.
Mein Instinkt ist es, dies in meinem Kopf als nur als -Konstruktor mit Argumenten umzufragen Konvertierkonstruktor [3], nicht als "spezielle Mitgliedsfunktion". Insbesondere: Überwinnen Sie den Nichttransfer des Allocators (Standardkonstruktion) und stellen Sie sich dies als syntaktischer Zucker vor, um das Äquivalent der Vektor-Template Vektor zu machen (inputit zuerst, inputit zuletzt, Constracator & Alloc = Alloc = Allocator ()). von Kopierkonstruktoren und Allokatoren? />[*]https://en.cppreference.com/w/cpp/memor ... nstruction
[*]https />https://en.cppreference.com/w/cpp/slang ... onstructor