[#boost-urls-url_view_base-persist]
= xref:boost.adoc[boost]::xref:boost/urls.adoc[urls]::xref:boost/urls/url_view_base.adoc[url&lowbar;view&lowbar;base]::persist
:relfileprefix: ../../../
:mrdocs:

Return a shared, persistent copy of the url

== Synopsis

Declared in `&lt;https://www.github.com/boostorg/url/blob/develop/include/boost/url/url_view_base.hpp#L341[boost&sol;url&sol;url&lowbar;view&lowbar;base&period;hpp]&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
std::shared&lowbar;ptr&lt;url&lowbar;view const&gt;
persist() const;
----

== Description

This function returns a read&hyphen;only copy of the url, with shared lifetime&period; The returned value owns (persists) the underlying string&period; 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&period;

== Example

[,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.
}
----
== Complexity

Linear in `this&hyphen;&gt;size()`&period;

== Exception Safety

Calls to allocate may throw&period;

== Return Value

A shared pointer to a read&hyphen;only url&lowbar;view&period;


[.small]#Created with https://www.mrdocs.com[MrDocs]#
