Telegram Group & Telegram Channel
How to: убираем типы с помощью std::decay_t

std::decay_t — один из самых полезных type traits в C++. Он имитирует процесс передачи параметра по значению, «разрушая» исходный тип.

🔄 Что именно делает decay_t?

• Убирает cv-квалификаторы
• Превращает ссылки в соответствующие типы без ссылок
• Преобразует массивы в указатели
• Преобразует функции в указатели на функции

💻 Пример:

#include <type_traits>
#include <iostream>

int main() {
// const int& -> int
static_assert(std::is_same_v<std::decay_t<const int&>, int>);

// int[10] -> int*
static_assert(std::is_same_v<std::decay_t<int[10]>, int*>);

// void(int) -> void(*)(int)
static_assert(std::is_same_v<std::decay_t<void(int)>, void(*)(int)>);

std::cout << "All assertions passed!" << std::endl;
}


🚀 Где это используется?

• В шаблонном программировании для упрощения работы с типами
• В std::make_shared и std::make_unique для определения типа создаваемого объекта
• При написании обобщенного кода, где нужна правильная дедукция типов

🔍 И да, название «decay» («разрушение») действительно отражает суть — тип «разрушается» до базового представления!

➡️ @cpp_geek



tg-me.com/cpp_geek/318
Create:
Last Update:

How to: убираем типы с помощью std::decay_t

std::decay_t — один из самых полезных type traits в C++. Он имитирует процесс передачи параметра по значению, «разрушая» исходный тип.

🔄 Что именно делает decay_t?

• Убирает cv-квалификаторы
• Превращает ссылки в соответствующие типы без ссылок
• Преобразует массивы в указатели
• Преобразует функции в указатели на функции

💻 Пример:


#include <type_traits>
#include <iostream>

int main() {
// const int& -> int
static_assert(std::is_same_v<std::decay_t<const int&>, int>);

// int[10] -> int*
static_assert(std::is_same_v<std::decay_t<int[10]>, int*>);

// void(int) -> void(*)(int)
static_assert(std::is_same_v<std::decay_t<void(int)>, void(*)(int)>);

std::cout << "All assertions passed!" << std::endl;
}


🚀 Где это используется?

• В шаблонном программировании для упрощения работы с типами
• В std::make_shared и std::make_unique для определения типа создаваемого объекта
• При написании обобщенного кода, где нужна правильная дедукция типов

🔍 И да, название «decay» («разрушение») действительно отражает суть — тип «разрушается» до базового представления!

➡️ @cpp_geek

BY C++ geek




Share with your friend now:
tg-me.com/cpp_geek/318

View MORE
Open in Telegram


telegram Telegram | DID YOU KNOW?

Date: |

What is Telegram?

Telegram’s stand out feature is its encryption scheme that keeps messages and media secure in transit. The scheme is known as MTProto and is based on 256-bit AES encryption, RSA encryption, and Diffie-Hellman key exchange. The result of this complicated and technical-sounding jargon? A messaging service that claims to keep your data safe.Why do we say claims? When dealing with security, you always want to leave room for scrutiny, and a few cryptography experts have criticized the system. Overall, any level of encryption is better than none, but a level of discretion should always be observed with any online connected system, even Telegram.

How to Buy Bitcoin?

Most people buy Bitcoin via exchanges, such as Coinbase. Exchanges allow you to buy, sell and hold cryptocurrency, and setting up an account is similar to opening a brokerage account—you’ll need to verify your identity and provide some kind of funding source, such as a bank account or debit card. Major exchanges include Coinbase, Kraken, and Gemini. You can also buy Bitcoin at a broker like Robinhood. Regardless of where you buy your Bitcoin, you’ll need a digital wallet in which to store it. This might be what’s called a hot wallet or a cold wallet. A hot wallet (also called an online wallet) is stored by an exchange or a provider in the cloud. Providers of online wallets include Exodus, Electrum and Mycelium. A cold wallet (or mobile wallet) is an offline device used to store Bitcoin and is not connected to the Internet. Some mobile wallet options include Trezor and Ledger.

telegram from cn


Telegram C++ geek
FROM USA