std:: remove_cv, std:: remove_const, std:: remove_volatile
From cppreference.net
C++
Metaprogramming library
| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++14)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Определено в заголовочном файле
<type_traits>
|
||
|
template
<
class
T
>
struct remove_cv ; |
(1) | (начиная с C++11) |
|
template
<
class
T
>
struct remove_const ; |
(2) | (начиная с C++11) |
|
template
<
class
T
>
struct remove_volatile ; |
(3) | (начиная с C++11) |
Предоставляет член-typedef
type
, который совпадает с
T
, за исключением того, что его старшие cv-квалификаторы удалены.
1)
Удаляет самый верхний
const
, или самый верхний
volatile
, или оба, если присутствуют.
2)
Удаляет самый верхний
const
.
3)
Удаляет самый верхний
volatile
.
Если программа добавляет специализации для любых шаблонов, описанных на этой странице, поведение не определено.
Содержание |
Типы членов
| Название | Определение |
type
|
тип
T
без cv-квалификаторов
|
Вспомогательные типы
|
template
<
class
T
>
using remove_cv_t = typename remove_cv < T > :: type ; |
(начиная с C++14) | |
|
template
<
class
T
>
using remove_const_t = typename remove_const < T > :: type ; |
(начиная с C++14) | |
|
template
<
class
T
>
using remove_volatile_t = typename remove_volatile < T > :: type ; |
(начиная с C++14) | |
Возможная реализация
template<class T> struct remove_cv { typedef T type; }; template<class T> struct remove_cv<const T> { typedef T type; }; template<class T> struct remove_cv<volatile T> { typedef T type; }; template<class T> struct remove_cv<const volatile T> { typedef T type; }; template<class T> struct remove_const { typedef T type; }; template<class T> struct remove_const<const T> { typedef T type; }; template<class T> struct remove_volatile { typedef T type; }; template<class T> struct remove_volatile<volatile T> { typedef T type; }; |
` и `` оставлен без изменений в соответствии с инструкциями. HTML-разметка и атрибуты также сохранены в оригинальном виде.
Пример
Удаление const/volatile из const volatile int * не изменяет тип, так как сам указатель не является ни const, ни volatile.
Запустить этот код
#include <type_traits> template<typename U, typename V> constexpr bool same = std::is_same_v<U, V>; static_assert ( same<std::remove_cv_t<int>, int> && same<std::remove_cv_t<const int>, int> && same<std::remove_cv_t<volatile int>, int> && same<std::remove_cv_t<const volatile int>, int> && // remove_cv only works on types, not on pointers not same<std::remove_cv_t<const volatile int*>, int*> && same<std::remove_cv_t<const volatile int*>, const volatile int*> && same<std::remove_cv_t<const int* volatile>, const int*> && same<std::remove_cv_t<int* const volatile>, int*> ); int main() {}
Смотрите также
|
(C++11)
|
проверяет, является ли тип константным
(шаблон класса) |
|
(C++11)
|
проверяет, является ли тип volatile-квалифицированным
(шаблон класса) |
|
(C++11)
(C++11)
(C++11)
|
добавляет
const
и/или
volatile
спецификаторы к заданному типу
(шаблон класса) |
|
(C++20)
|
объединяет
std::remove_cv
и
std::remove_reference
(шаблон класса) |