News for hackers. Stuff that matters.
Re:Deprecating Raw Pointers in C++20 by evincarofautumn on Sunday April 01, 2018 @09:47AM (#16728225)
Honestly this wouldn’t be a bad idea for consistency, teaching, and template programming purposes:

    namespace std {
        template<typename T>
        using raw_ptr = T*;
    }

    // mutable pointer to const value
    int const *a_old;
    std::raw_ptr<int const> a_new;
    std::raw_ptr<const int> a_new_var;

    // const pointer to mutable value
    int *const b_old;
    std::raw_ptr<int> const b_new;
    const std::raw_ptr<int> b_new_var;

    // const pointer to const value
    int const *const c_old;
    std::raw_ptr<int const> const c_new;
    const std::raw_ptr<const int> c_new_var;
I’ve actually used this before to parameterise a struct/class with an ownership policy, for example:

    template<template<typename T, typename...> class P>
    struct Wrapper {
        P<int> value;
    };
Now Wrapper<std::raw_ptr> is a non-owning Wrapper, while Wrapper<std::unique_ptr> is an owning one.

There are no comments on this comment yet.