:relfileprefix: ../../../
[#boost-urls-segments_ref-insert-09]

== xref:boost.adoc[pass:[boost]]::xref:boost/urls.adoc[pass:[urls]]::xref:boost/urls/segments_ref.adoc[pass:[segments_ref]]::insert


Insert segments


=== Synopsis

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

[source,cpp,subs="verbatim,macros,-callouts"]
----
xref:boost/urls/segments_base/iterator.adoc[iterator]
insert(
    xref:boost/urls/segments_base/iterator.adoc[iterator] before,
    std::initializer_list<core::string_view> init);
----

=== Description


This function inserts the segments
in an initializer list before the
specified position.
Reserved characters in the list are
percent-escaped in the result.



All iterators that are equal to
`before` or come after are invalidated.
[NOTE]

None of the character buffers referenced
by the list may overlap the character
buffer of the underlying url, or else
the behavior is undefined.
[,cpp]
----
url u( "/file.txt" );

u.segments().insert( u.segments().begin(), { "path", "to" } );
----

=== Linear in `init.size() + this-&gt;url().encoded_resource().size()`.

=== Strong guarantee.

Calls to allocate may throw.




=== Return Value


An iterator to the first
element inserted, or `before` if
`init.size() &equals;&equals; 0`.



=== Parameters

|===
| Name | Description 

| *before*
| 
An iterator before which
the list is inserted. This may
be equal to `end()`.

| *init*
| 
The list of segments to insert.

|===




