CPPPROGLIB Telegram 4711
🌟 Выведение размера массива

Для std::array размер в общем случае задаётся вручную
std::array<int, 2> test{ 2,3 };


Начиная с C++17 можно оставить вывод размера компилятору
std::array test{ 2,3 };


Но если необходимо использовать шаблоны, то можно воспользоваться шаблонной магией
template<typename T, size_t N>
int size(const std::array<T, N>& types)
{
    return N;
}
👍17



tgoop.com/cppproglib/4711
Create:
Last Update:

🌟 Выведение размера массива

Для std::array размер в общем случае задаётся вручную

std::array<int, 2> test{ 2,3 };


Начиная с C++17 можно оставить вывод размера компилятору
std::array test{ 2,3 };


Но если необходимо использовать шаблоны, то можно воспользоваться шаблонной магией
template<typename T, size_t N>
int size(const std::array<T, N>& types)
{
    return N;
}

BY Библиотека C/C++ разработчика | cpp, boost, qt


Share with your friend now:
tgoop.com/cppproglib/4711

View MORE
Open in Telegram


Telegram News

Date: |

Concise Avoid compound hashtags that consist of several words. If you have a hashtag like #marketingnewsinusa, split it into smaller hashtags: “#marketing, #news, #usa. A Hong Kong protester with a petrol bomb. File photo: Dylan Hollingsworth/HKFP. Developing social channels based on exchanging a single message isn’t exactly new, of course. Back in 2014, the “Yo” app was launched with the sole purpose of enabling users to send each other the greeting “Yo.” In the next window, choose the type of your channel. If you want your channel to be public, you need to develop a link for it. In the screenshot below, it’s ”/catmarketing.” If your selected link is unavailable, you’ll need to suggest another option.
from us


Telegram Библиотека C/C++ разработчика | cpp, boost, qt
FROM American