Обложка канала

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

14677 @cppproglib

Полезные материалы по всему, что может быть полезно плюсовику/сишнику.

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

4 года назад
Открыть в
An example where inline constexpr makes a difference

The C++11 and C++14 standard libraries defined many constexpr global variables like this: constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t(); constexpr allocator_arg_t allocator_arg = allocator_arg_t(); constexpr error_type error_ctype = /*unspecified*/; constexpr defer_lock_t defer_lock{}; constexpr in_place_t in_place{}; constexpr nullopt_t nullopt(/*unspecified*/{}); In C++17, all of these constexpr variables were respecified as inline constexpr variables. The inline keyword here means the same thing as it does on an inline function: “This entity might be defined in multiple TUs; all those definitions are identical; merge them into one definition at link time.” If you look at the generated code for one of these variables in C++14, you’ll see something like this (Godbolt):

quuxplusone.github.io