CPPPROGLIB Telegram 6009
⚡️ Constexpr эволюция — от C++11 до C++23

Хотите больше вычислений во время компиляции для максимальной производительности?

constexpr развивался от простых функций в C++11 до полноценного compile-time программирования в C++20. Позволяет выполнять сложную логику на этапе компиляции.


💡 C++11 — только простые функции:

constexpr int factorial(int n) {
return n <= 1 ? 1 : n * factorial(n - 1);
}



💡 C++14 — циклы и условия:

constexpr int sum_array(const int* arr, size_t size) {
int sum = 0;
for (size_t i = 0; i < size; ++i) {
sum += arr[i];
}
return sum;
}



💡 C++20 — std::vector и dynamic memory:

constexpr std::vector<int> make_sequence(int n) {
std::vector<int> result;
for (int i = 0; i < n; ++i) {
result.push_back(i * i);
}
return result;
}



💡 C++23 — constexpr std::string:

constexpr std::string process_text() {
std::string result = "Hello, ";
result += "constexpr world!";
return result;
}

constexpr auto text = process_text(); // Во время компиляции!



Библиотека C/C++ разработчика

#буст
Please open Telegram to view this post
VIEW IN TELEGRAM
🔥143👍3



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

⚡️ Constexpr эволюция — от C++11 до C++23

Хотите больше вычислений во время компиляции для максимальной производительности?

constexpr развивался от простых функций в C++11 до полноценного compile-time программирования в C++20. Позволяет выполнять сложную логику на этапе компиляции.


💡 C++11 — только простые функции:

constexpr int factorial(int n) {
return n <= 1 ? 1 : n * factorial(n - 1);
}



💡 C++14 — циклы и условия:

constexpr int sum_array(const int* arr, size_t size) {
int sum = 0;
for (size_t i = 0; i < size; ++i) {
sum += arr[i];
}
return sum;
}



💡 C++20 — std::vector и dynamic memory:

constexpr std::vector<int> make_sequence(int n) {
std::vector<int> result;
for (int i = 0; i < n; ++i) {
result.push_back(i * i);
}
return result;
}



💡 C++23 — constexpr std::string:

constexpr std::string process_text() {
std::string result = "Hello, ";
result += "constexpr world!";
return result;
}

constexpr auto text = process_text(); // Во время компиляции!



Библиотека C/C++ разработчика

#буст

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


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

View MORE
Open in Telegram


Telegram News

Date: |

Don’t publish new content at nighttime. Since not all users disable notifications for the night, you risk inadvertently disturbing them. But a Telegram statement also said: "Any requests related to political censorship or limiting human rights such as the rights to free speech or assembly are not and will not be considered." While the character limit is 255, try to fit into 200 characters. This way, users will be able to take in your text fast and efficiently. Reveal the essence of your channel and provide contact information. For example, you can add a bot name, link to your pricing plans, etc. SUCK Channel Telegram Add the logo from your device. Adjust the visible area of your image. Congratulations! Now your Telegram channel has a face Click “Save”.!
from us


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