मेरे आश्चर्य के लिए, मुझे एक गैर-प्रतिलिपि आवंटक के साथ std::vector::get_allocator()
का उपयोग करने का प्रयास करते समय एक त्रुटि मिली। std::vector::get_allocator()
क्यों मूल्य-दर-वापसी द्वारा संदर्भित नहीं करता है?std :: vector :: get_allocator() मूल्य-दर-वापसी क्यों करता है?
template<typename T>
class nc_allocator {
public:
using value_type = T;
nc_allocator(nc_allocator const&) = delete;
nc_allocator& operator=(nc_allocator const&) = delete;
// Other required members.
};
std::vector<int, nc_allocator<int>> v;
// boom: use of deleted function
// 'nc_allocator<T>::nc_allocator(const nc_allocator<T>&) [with T = int]'
v.get_allocator();
मुझे संदेह है कि आवंटकों के उदाहरणों को हैंडल की तरह माना जाना चाहिए। इसका प्रमाण यह है कि दो आवंटकों को केवल तभी माना जाता है जब कोई अन्य वस्तुओं को हटा सकता है। –