:relfileprefix: ../../../
[#boost-urls-url_view_base-persist]

== xref:boost.adoc[pass:[boost]]::xref:boost/urls.adoc[pass:[urls]]::xref:boost/urls/url_view_base.adoc[pass:[url_view_base]]::persist


Return a shared, persistent copy of the url


=== Synopsis

Declared in header `<https://www.github.com/boostorg/url/blob/develop/include/boost/url/url_view_base.hpp#L312[boost/url/url_view_base.hpp,window=blank_]>`

[source,cpp,subs="verbatim,macros,-callouts"]
----
std::shared_ptr<xref:boost/urls/url_view.adoc[url_view] const>
persist() const;
----

=== Description


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.
[,cpp]
----
std::shared_ptr< url_view const > sp;
{
    std::string s( "http://example.com" );
    url_view u( s );                        // u references characters in s

    assert( u.data() == s.data() );         // same buffer

    sp = u.persist();

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

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

=== Linear in `this-&gt;size()`.

=== Calls to allocate may throw.








