Search code examples
c++autoallocator

C++03 equivalent for auto in the context of obtaining an allocator


auto source_allocator = source.get_allocator();

Is there a way of replacing auto in the above with something C++03/98-friendly, in the event where the type of allocator is not known in advance?


Solution

  • Based on what you posted in the comments, it sounds like you're trying to do this inside a template.

    Assuming you are expecting your templated type to be a std::container, or something compatible, you can do this: typename T::allocator_type in place of auto.

    https://godbolt.org/z/Pda77vjox