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

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: "Kopieren Sie Konstrukt" aus dem Behälter mit potenziell anderem Allocator

by Anonymous » 05 Apr 2025, 09:09

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

Top