Files
cppdraft_translate/cppdraft/declval.md
2025-10-25 03:02:53 +03:00

46 lines
1.6 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[declval]
# 22 General utilities library [[utilities]](./#utilities)
## 22.2 Utility components [[utility]](utility#declval)
### 22.2.6 Function template declval [declval]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L508)
The library provides the function template declval to simplify the definition of
expressions which occur as [unevaluated operands](expr.context#def:unevaluated_operand "7.2.3Context dependence[expr.context]")[.](#1.sentence-1)
[🔗](#lib:declval)
`template<class T> add_rvalue_reference_t<T> declval() noexcept; // as unevaluated operand
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L518)
*Mandates*: This function is not odr-used ([[basic.def.odr]](basic.def.odr#term.odr.use "6.3One-definition rule"))[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L522)
*Remarks*: The template parameter T of declval may be an incomplete type[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/utilities.tex#L526)
[*Example [1](#example-1)*:
template<class To, class From> decltype(static_cast<To>(declval<From>())) convert(From&&); declares a function template convert which only participates in overload resolution if the
type From can be explicitly converted to type To[.](#4.sentence-1)
For another example see class
template common_type ([[meta.trans.other]](meta.trans.other "21.3.9.7Other transformations"))[.](#4.sentence-2)
— *end example*]