[#boost-urls-params_encoded_ref-set-07]
= xref:boost.adoc[boost]::xref:boost/urls.adoc[urls]::xref:boost/urls/params_encoded_ref.adoc[params&lowbar;encoded&lowbar;ref]::set
:relfileprefix: ../../../
:mrdocs:


Set a value

== Synopsis


Declared in `&lt;https://www.github.com/boostorg/url/blob/develop/include/boost/url/params_encoded_ref.hpp#L951[boost&sol;url&sol;params&lowbar;encoded&lowbar;ref&period;hpp]&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
xref:boost/urls/params_encoded_base/iterator.adoc[iterator]
set(
    xref:boost/urls/pct_string_view.adoc[pct&lowbar;string&lowbar;view] key,
    xref:boost/urls/pct_string_view.adoc[pct&lowbar;string&lowbar;view] value,
    xref:boost/urls/ignore_case_param.adoc[ignore&lowbar;case&lowbar;param] ic = &lcub;&rcub;);
----

== Description


This function performs one of two        actions depending on the value of        `this&hyphen;&gt;contains( key, ic )`&period;

* If key is contained in the view        then one of the matching params has
        its value changed to the specified value&period;        The remaining params with a matching
        key are erased&period; Otherwise,
* If 
`key`
 is not contained in the        view, then the function apppends the
        param 
`&lcub; key, value &rcub;`
&period;

All iterators are invalidated&period;

[NOTE]
The strings passed in must not come        from the element being replaced,        or else the behavior is undefined&period;


=== Example

[,cpp]
----
url u( "?id=42&id=69" );

u.encoded_params().set( "id", "none" );

assert( u.encoded_params().count( "id" ) == 1 );
----

=== Postconditions

[,cpp]
----
this->count( key, ic ) == 1 && this->find( key, ic )->value == value
----

=== Complexity

Linear in `this&hyphen;&gt;url()&period;encoded&lowbar;query()&period;size()`&period;


=== Exception Safety

Strong guarantee&period;        Calls to allocate may throw&period;        Exceptions thrown on invalid input&period;

Set a value

This function performs one of two        actions depending on the value of        `this&hyphen;&gt;contains( key, ic )`&period;

* If key is contained in the view        then one of the matching params has
        its value changed to the specified value&period;        The remaining params with a matching
        key are erased&period; Otherwise,
* If 
`key`
 is not contained in the        view, then the function apppends the
        param 
`&lcub; key, value &rcub;`
&period;

All iterators are invalidated&period;

[NOTE]
The strings passed in must not come        from the element being replaced,        or else the behavior is undefined&period;


=== Example

[,cpp]
----
url u( "?id=42&id=69" );

u.encoded_params().set( "id", "none" );

assert( u.encoded_params().count( "id" ) == 1 );
----

=== Postconditions

[,cpp]
----
this->count( key, ic ) == 1 && this->find( key, ic )->value == value
----

=== Complexity

Linear in `this&hyphen;&gt;url()&period;encoded&lowbar;query()&period;size()`&period;


=== Exception Safety

Strong guarantee&period;        Calls to allocate may throw&period;        Exceptions thrown on invalid input&period;



== Exceptions


|===
| Name | Thrown on

| `system&lowbar;error`
| `key` or `value` contain an invalid        percent&hyphen;encoding&period;


| `system&lowbar;error`
| `key` or `value` contain an invalid        percent&hyphen;encoding&period;


|===

== Return Value


An iterator to the appended        or modified element&period;



== Parameters


|===
| Name | Description

| *key*
| The key to match&period;        By default, a case&hyphen;sensitive        comparison is used&period;


| *value*
| The value to assign&period; The        empty string still counts as a value&period;        That is, `has&lowbar;value` for the element        is true&period;


| *ic*
| An optional parameter&period; If        the value xref:boost/urls/ignore_case.adoc[ignore&lowbar;case] is passed        here, the comparison is        case&hyphen;insensitive&period;


| *key*
| The key to match&period;        By default, a case&hyphen;sensitive        comparison is used&period;


| *value*
| The value to assign&period; The        empty string still counts as a value&period;        That is, `has&lowbar;value` for the element        is true&period;


| *ic*
| An optional parameter&period; If        the value xref:boost/urls/ignore_case.adoc[ignore&lowbar;case] is passed        here, the comparison is        case&hyphen;insensitive&period;


|===



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