Search code examples
c++design-patternsadapterstandardsstd

What is an adaptor in the C++ standard? How does it relate to the adapter design pattern?


The C++ standard uses the word adaptors several times:

  • Allocator adaptors (std::scoped_allocator_adaptor)
  • Container adaptors (std::queue, std::priority_queue, std::stack)
  • Iterator adaptors (std::reverse_iterator, std::move_iterator)

It does not seem that the word itself is defined in the standard. I was thinking that the word was used in reference to design patterns, but it seems that in the adapter design pattern, the adapter should only adapt the interface, not the behavior.

Questions: Therefore I was wondering:

  • What would be the approximate definition of an adaptor in the C++ standard?
  • Does it correspond to the adapter design pattern?
  • If not, what would be the design pattern that matches the best what an adaptor is in the C++ standard (adapter, proxy, facade, decorator...)?

Solution

  • The word "adapter" is not used in some technical, design-pattern sense. It is used as the English word: a thing that adapts. There is no need for a more rigorous definition than that.

    Container adapters modify the interface of containers. Iterator adapters modify the interface of iterators. And so forth. You're really overthinking the whole thing.