You are viewing a single thread.
View all comments
16 points

C++: Nuh, uh …

template <typename T>
concept Crackable = requires(T obj) {
    { obj.crack() };
};

auto crack(Crackable auto& nut) {
    nut.crack();
}
permalink
report
reply
2 points
*

This is dangerous. The object might not have the crack() method, and this bloats the compiled size by a lot if you use it with different types. There’s also no reason I can see to use concepts here. The saner way would probably be to use inheritance and objects to mimic Java interfaces.

permalink
report
parent
reply
5 points

This is dangerous

Well, they say you do have to be over 18 to use Concepts

permalink
report
parent
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 3.2K

    Monthly active users

  • 1K

    Posts

  • 37K

    Comments