DEV Community

Discussion on: const and smart pointers

Collapse
 
pgradot profile image
Pierre Gradot

42, 52, 666. I see that we use the same magic dummy numbers
😁

Don't forget the const on the right-hand side!

Shouldn't we use auto instead of repeating the data type?

#include <memory>

int main() {
    const std::unique_ptr<const int> p = std::make_unique<const int>(42);
    const auto o = std::make_unique<const int>(51);
    static_assert(std::is_same_v<decltype(p), decltype(o)>);
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
sandordargo profile image
Sandor Dargo

That's true, probably auto would be the best!