[func.wrap.copy.ctor]

# 22 General utilities library [[utilities]](./#utilities)

## 22.10 Function objects [[function.objects]](function.objects#func.wrap.copy.ctor)

### 22.10.17 Polymorphic function wrappers [[func.wrap]](func.wrap#copy.ctor)

#### 22.10.17.5 Copyable wrapper [[func.wrap.copy]](func.wrap.copy#ctor)

#### 22.10.17.5.3 Constructors, assignments, and destructor [func.wrap.copy.ctor]

[ð](#:copyable_function::is-callable-from)

`template<class VT>
  static constexpr bool is-callable-from = see below;
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14573)

If *noex* is true,*is-callable-from*<VT> is equal to:is_nothrow_invocable_r_v<R, VT cv *ref*, ArgTypes...> && is_nothrow_invocable_r_v<R, VT *inv-quals*, ArgTypes...>

Otherwise, *is-callable-from*<VT> is equal to:is_invocable_r_v<R, VT cv *ref*, ArgTypes...> && is_invocable_r_v<R, VT *inv-quals*, ArgTypes...>

[ð](#lib:copyable_function,constructor)

`copyable_function() noexcept;
copyable_function(nullptr_t) noexcept;
`

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14594)

*Postconditions*: *this has no target object[.](#2.sentence-1)

[ð](#lib:copyable_function,constructor_)

`copyable_function(const copyable_function& f);
`

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14605)

*Postconditions*: *this has no target object if f had no target object[.](#3.sentence-1)

Otherwise, the target object of *this is a copy of the target object of f[.](#3.sentence-2)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14611)

*Throws*: Any exception thrown by the initialization of the target object[.](#4.sentence-1)

May throw bad_alloc[.](#4.sentence-2)

[ð](#lib:copyable_function,constructor__)

`copyable_function(copyable_function&& f) noexcept;
`

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14623)

*Postconditions*: The target object of *this is
the target object f had before construction, andf is in a valid state with an unspecified value[.](#5.sentence-1)

[ð](#lib:copyable_function,constructor___)

`template<class F> copyable_function(F&& f);
`

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14636)

Let VT be decay_t<F>[.](#6.sentence-1)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14639)

*Constraints*: 

- [(7.1)](#7.1)

remove_cvref_t<F> is not the same type as copyable_function, and

- [(7.2)](#7.2)

remove_cvref_t<F> is not a specialization of in_place_type_t, and

- [(7.3)](#7.3)

*is-callable-from*<VT> is true[.](#7.sentence-1)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14650)

*Mandates*: 

- [(8.1)](#8.1)

is_constructible_v<VT, F> is true, and

- [(8.2)](#8.2)

is_copy_constructible_v<VT> is true[.](#8.sentence-1)

[9](#9)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14659)

*Preconditions*: VT meets the [*Cpp17Destructible*](utility.arg.requirements#:Cpp17Destructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") and[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements[.](#9.sentence-1)

[10](#10)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14664)

*Postconditions*: *this has no target object if any of the following hold:

- [(10.1)](#10.1)

f is a null function pointer value, or

- [(10.2)](#10.2)

f is a null member pointer value, or

- [(10.3)](#10.3)

remove_cvref_t<F> is a specialization of
the copyable_function class template,
and f has no target object[.](#10.sentence-1)

Otherwise, *this has a target object of type VT direct-non-list-initialized with std​::​forward<F>(f)[.](#10.sentence-2)

[11](#11)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14680)

*Throws*: Any exception thrown by the initialization of the target object[.](#11.sentence-1)

May throw bad_alloc unless VT is
a function pointer or a specialization of reference_wrapper[.](#11.sentence-2)

[ð](#lib:copyable_function,constructor____)

`template<class T, class... Args>
  explicit copyable_function(in_place_type_t<T>, Args&&... args);
`

[12](#12)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14694)

Let VT be decay_t<T>[.](#12.sentence-1)

[13](#13)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14697)

*Constraints*: 

- [(13.1)](#13.1)

is_constructible_v<VT, Args...> is true, and

- [(13.2)](#13.2)

*is-callable-from*<VT> is true[.](#13.sentence-1)

[14](#14)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14706)

*Mandates*: 

- [(14.1)](#14.1)

VT is the same type as T, and

- [(14.2)](#14.2)

is_copy_constructible_v<VT> is true[.](#14.sentence-1)

[15](#15)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14715)

*Preconditions*: VT meets the [*Cpp17Destructible*](utility.arg.requirements#:Cpp17Destructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") and[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements[.](#15.sentence-1)

[16](#16)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14720)

*Postconditions*: *this has a target object of type VT direct-non-list-initialized with std​::​forward<Args>​(args)...[.](#16.sentence-1)

[17](#17)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14725)

*Throws*: Any exception thrown by the initialization of the target object[.](#17.sentence-1)

May throw bad_alloc unless VT is
a pointer or a specialization of reference_wrapper[.](#17.sentence-2)

[ð](#lib:copyable_function,constructor_____)

`template<class T, class U, class... Args>
  explicit copyable_function(in_place_type_t<T>, initializer_list<U> ilist, Args&&... args);
`

[18](#18)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14739)

Let VT be decay_t<T>[.](#18.sentence-1)

[19](#19)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14742)

*Constraints*: 

- [(19.1)](#19.1)

is_constructible_v<VT, initializer_list<U>&, Args...> istrue, and

- [(19.2)](#19.2)

*is-callable-from*<VT> is true[.](#19.sentence-1)

[20](#20)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14752)

*Mandates*: 

- [(20.1)](#20.1)

VT is the same type as T, and

- [(20.2)](#20.2)

is_copy_constructible_v<VT> is true[.](#20.sentence-1)

[21](#21)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14761)

*Preconditions*: VT meets the [*Cpp17Destructible*](utility.arg.requirements#:Cpp17Destructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") and[*Cpp17CopyConstructible*](utility.arg.requirements#:Cpp17CopyConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements[.](#21.sentence-1)

[22](#22)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14766)

*Postconditions*: *this has a target object of type VT direct-non-list-initialized withilist, std​::​forward<Args>(args)...[.](#22.sentence-1)

[23](#23)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14772)

*Throws*: Any exception thrown by the initialization of the target object[.](#23.sentence-1)

May throw bad_alloc unless VT is
a pointer or a specialization of reference_wrapper[.](#23.sentence-2)

[ð](#lib:operator=,copyable_function)

`copyable_function& operator=(const copyable_function& f);
`

[24](#24)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14785)

*Effects*: Equivalent to: copyable_function(f).swap(*this);

[25](#25)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14789)

*Returns*: *this[.](#25.sentence-1)

[ð](#lib:operator=,copyable_function_)

`copyable_function& operator=(copyable_function&& f);
`

[26](#26)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14800)

*Effects*: Equivalent to: copyable_function(std​::​move(f)).swap(*this);

[27](#27)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14804)

*Returns*: *this[.](#27.sentence-1)

[ð](#lib:operator=,copyable_function__)

`copyable_function& operator=(nullptr_t) noexcept;
`

[28](#28)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14815)

*Effects*: Destroys the target object of *this, if any[.](#28.sentence-1)

[29](#29)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14819)

*Returns*: *this[.](#29.sentence-1)

[ð](#lib:operator=,copyable_function___)

`template<class F> copyable_function& operator=(F&& f);
`

[30](#30)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14830)

*Effects*: Equivalent to: copyable_function(std​::​forward<F>(f)).swap(*this);

[31](#31)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14834)

*Returns*: *this[.](#31.sentence-1)

[ð](#lib:copyable_function,destructor)

`~copyable_function();
`

[32](#32)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L14845)

*Effects*: Destroys the target object of *this, if any[.](#32.sentence-1)
