[libcxx-commits] [libcxx] [libc++] Add __pointer_int_pair (PR #94324)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 6 08:10:05 PDT 2024


ldionne wrote:


> When in doubt, keep behaviors separate until enough common patterns emerge over time that justify the coupling. On a small scale, managing duplication can be simpler than resolving a premature abstraction’s complexity. In early stages of development, tolerate a little duplication and wait to abstract. [1](https://testing.googleblog.com/2024/05/dont-dry-your-code-prematurely.html)

`pointer_int_pair` is an abstraction that, if we had it, we could have used in a few other places like `optional` and `expected`. Of course, we can't make use of the abstraction until we have an implementation of it.

I generally agree with the statement "don't try to DRY your code too early", however `pointer_int_pair` is a well understood abstraction we're taking from the LLVM code base, we have a few examples of classes that could have used it, and we have an immediately upcoming need for it for `move_only_function`. I don't think this is a case of premature DRYing.

> 
> This is not the only unused abstraction that's been committed to libc++ for move_only_function recently. When looking for the implementation of `move_only_function` I found `__small_buffer` which is similarly unused.

`__small_buffer` was in fact used outside of `move_only_function` after it was introduced, but those uses were reverted due to a "regression" within Google that we still don't have a reproducer for, so we never really picked that up again.

https://github.com/llvm/llvm-project/pull/94324


More information about the libcxx-commits mailing list