Quote:
Originally Posted by feisty2
or a bit more organized with C++ 14..
Code:
#include <cstdint>
auto operator""ElementsLUTTable(size_t length) {
struct LUTTable final {
int32_t *RGBToLab = nullptr;
int32_t *LabToRGB = nullptr;
LUTTable(size_t length = 0) {
RGBToLab = new int32_t[length];
LabToRGB = new int32_t[length];
}
LUTTable(const LUTTable &) = delete;
LUTTable(LUTTable &&obj) {
RGBToLab = obj.RGBToLab;
LabToRGB = obj.LabToRGB;
obj.RGBToLab = nullptr;
obj.LabToRGB = nullptr;
}
auto &operator=(const LUTTable &) = delete;
auto &operator=(LUTTable &&obj) {
if (this != &obj) {
RGBToLab = obj.RGBToLab;
LabToRGB = obj.LabToRGB;
obj.RGBToLab = nullptr;
obj.LabToRGB = nullptr;
}
return *this;
}
~LUTTable() {
delete[] RGBToLab;
delete[] LabToRGB;
}
};
return LUTTable(length);
}
auto table = 16777216ElementsLUTTable;
|
One component of good coding is explicit intent. Your example is obscure. Does it even work? Isn't the structure declared in the scope of operator? Or does "auto" pull the declaration outside?