:relfileprefix: ../../../
[#boost-urls-segments_encoded_ref-assign]

== xref:boost.adoc[pass:[boost]]::xref:boost/urls.adoc[pass:[urls]]::xref:boost/urls/segments_encoded_ref.adoc[pass:[segments_encoded_ref]]::assign

  


Assign segments



=== Synopsis
  

[source,cpp,subs="verbatim,macros,-callouts"]
----
void
xref:boost/urls/segments_encoded_ref/assign-0e.adoc[pass:[assign]](std::initializer_list<xref:boost/urls/pct_string_view.adoc[pct_string_view]> init);
----

[source,cpp,subs="verbatim,macros,-callouts"]
----
template<class FwdIt>
void
xref:boost/urls/segments_encoded_ref/assign-0b.adoc[pass:[assign]](
    FwdIt first,
    FwdIt last);
----
  
=== Description


The existing contents are replaced
by a copy of the contents of the
initializer list.
Reserved characters in the list are
automatically escaped.
Escapes in the list are preserved.



All iterators 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;

u.segments().assign( {"path", "to", "file.txt"} );
----

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

=== Strong guarantee.

Calls to allocate may throw.
Exceptions thrown on invalid input.


=== Exceptions

|===
| Name | Thrown on

| `The`
| 
list contains an invalid percent-encoding.

|===


=== Parameters

|===
| Name | Description 

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

| *first,*
| 
last The range of segments
to assign.

|===




