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

Programme in C++. Entwicklerforum
Anonymous
 "Kopieren Sie Konstrukt" aus dem Behälter mit potenziell anderem Allocator

Post 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

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post