Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Return a shared, persistent copy of the url.

std::shared_ptr< url_view const >
persist() const;

This function returns a read-only copy of the url, with shared lifetime. The returned value owns (persists) the underlying string. The algorithm used to create the value minimizes the number of individual memory allocations, making it more efficient than when using direct standard library functions.

std::shared_ptr< url_view const > sp;
    std::string s( "" );
    url_view u( s );                        // u references characters in s

    assert( == );         // same buffer

    sp = u.persist();

    assert( sp->data() != );       // different buffer
    assert( sp->buffer() == s);             // same contents

    // s is destroyed and thus u
    // becomes invalid, but sp remains valid.

Linear in this->size().

Exception Safety

Calls to allocate may throw.