Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7945319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:49:31+00:00 2026-06-04T00:49:31+00:00

std::allocator ‘s construct and destroy member functions are parameterized on the type of the

  • 0

std::allocator‘s construct and destroy member functions are parameterized on the type of the element to construct:

template<class T>
  class allocator
{
  public:
    typedef T value_type;
    typedef T* pointer;

    template<class U, class... Args>
      void construct(U *p, Args&&... args);

    template<class U>
      void destroy(U *p);

  ...
};

What’s the rationale for this? Why don’t they take either value_type* or pointer? It seems like allocator<T> should only know how to construct or destroy objects of type T.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:49:32+00:00Added an answer on June 4, 2026 at 12:49 am

    It’s for the same reason that allocators are required to have the rebind<U> typedef: because many containers never allocate Ts.

    Take linked lists. These allocate nodes, each one of which contains a T as a member. So allocators are required to be able to allocate some type that they don’t know of (via rebind<U>). However, that requires a copy operation: it requires creating a new allocator of the type rebind<U>::other.

    It’s better to avoid that when possible. Therefore, for construction and destruction, allocators are required to do the appropriate operations on any type, such as the linked list’s internal node types. This also makes it possible for the linked list’s internal node type to have Allocator::construct/destruct as friend functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: template<typename T, typename Allocator = std::allocator<T> > class Carray
I've got an extremely basic allocator: template<typename T> struct Allocator : public std::allocator<T> {
How can instantiate this template struct? template<typename T, template<typename, template <typename> class D= std::allocator
I have a class with a static std::map member variable that maps char s
I have a template class that contains a std::map that stores pointers to T
Is this possible? #include <map> class Example { private: std::map<std::string, std::string, less<std::string>, std::allocator< CustomPair<std::string,
The code below gives the error: error: type ‘std::list<T,std::allocator<_Tp1> >’ is not derived from
I am having trouble using a private std::map variable from within a class template.
1>GameWinMain.obj : error LNK2005: bool __cdecl BPredicate(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct
#ifndef MIGRATINGUSER_H #define MIGRATINGUSER_H #include <iostream> using namespace std; class MigratingUser { public: void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.