1

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...)?
4
  • 2
    I suspect most of those predates the book of 4 book that coined the name. Nov 16, 2018 at 18:38
  • facade might be best. It implements a particular interface on top of an already defined thing. Nov 16, 2018 at 18:39
  • Fun Fact: we see the same phenomenon in the Java world with old classes like MouseAdapter. A sign of the times?
    – jaco0646
    Nov 16, 2018 at 21:02
  • @jaco0646 I just looked into the old history of C++. The word adaptor for iterators was already used in 1994. For containers it's the case in 1995.
    – Vincent
    Nov 16, 2018 at 22:04

1 Answer 1

9

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.