std::add_cv
STD:添加[医]简历,STD::[医]Const,STD::[医]易挥发
Defined in header | | |
---|---|---|
template< class T > struct add_cv; | (1) | (since C++11) |
template< class T > struct add_const; | (2) | (since C++11) |
template< class T > struct add_volatile; | (3) | (since C++11) |
提供成员类型胡枝子f。type
这和T
,但它的cv-限定符添加%28,除非T
是一个函数,一个引用,或者已经有这个cv-限定符%29.
1%29加两者const
和volatile
...
2%29加const
...
3%29加volatile
...
成员类型
Name | Definition |
---|---|
type | the type T with the cv-qualifier |
帮助者类型
template< class T > using add_cv_t = typename add_cv | | (since C++14) |
---|---|---|
template< class T > using add_const_t = typename add_const<T>::type; | | (since C++14) |
template< class T > using add_volatile_t = typename add_volatile<T>::type; | | (since C++14) |
可能的实施
模板<class T>结构添加[医]CV<class T>结构添加[医]模板<class T>结构添加[医]易挥发的{tyduf挥发性T型;};
*。
例
二次
#include <iostream>
#include <type_traits>
struct foo
{
void m() { std::cout << "Non-cv\n"; }
void m() const { std::cout << "Const\n"; }
};
template <class T>
void call_m()
{
T().m(
}
int main()
{
call_m<foo>(
call_m<std::add_const<foo>::type>(
}
二次
产出:
二次
Non-cv
Const
二次
另见
is_const (C++11) | checks if a type is const-qualified (class template) |
---|---|
is_volatile (C++11) | checks if a type is volatile-qualified (class template) |
remove_cvremove_constremove_volatile (C++11)(C++11)(C++11) | removes const or/and volatile specifiers from the given type (class template) |
as_const (C++17) | obtains a reference to const to its argument (function template) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。