Код похож на этот :
Код: Выделить всё
#include
enum class Format {
UINT8,
UINT16
};
struct FormatInfo {
const char* name = nullptr;
int maxVal = 0;
constexpr explicit FormatInfo(Format fmt) {
auto set = [this](const auto&... args) constexpr {
std::tie(name, maxVal) = std::make_tuple(args...);
};
switch(fmt) {
case Format::UINT8: set("uint8", 255); break;
case Format::UINT16: set("uint16", 65535); break;
}
}
};
int main() {
FormatInfo info(Format::UINT8); // ok
constexpr FormatInfo info2(Format::UINT8); // fails
}
Создание самой лямбды constexpr (
Код: Выделить всё
constexpr auto set = ...
Есть ли способ заставить это работать в C++17?
Подробнее здесь: https://stackoverflow.com/questions/782 ... ith-stdtie