Commit: d546905f1dad4b0c1185c29742851f748710bd93 Author: Jacques Lucke Date: Sun Mar 21 12:33:18 2021 +0100 Branches: temp-any-instead-of-variant https://developer.blender.org/rBd546905f1dad4b0c1185c29742851f748710bd93
replace std::variant with std::any =================================================================== M source/blender/editors/space_spreadsheet/spreadsheet_column_layout.cc M source/blender/editors/space_spreadsheet/spreadsheet_column_layout.hh =================================================================== diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.cc b/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.cc index 00724ffd4b0..175bd294345 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.cc +++ b/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.cc @@ -118,9 +118,8 @@ class ColumnLayoutDrawer : public SpreadsheetDrawer { CellValue cell_value; column.get_value(real_index, cell_value); - if (std::holds_alternative<int>(cell_value.value)) { - const int value = *std::get_if<int>(&cell_value.value); - const std::string value_str = std::to_string(value); + if (const int *value = std::any_cast<int>(&cell_value.value)) { + const std::string value_str = std::to_string(*value); uiDefIconTextBut(params.block, UI_BTYPE_LABEL, 0, @@ -137,10 +136,9 @@ class ColumnLayoutDrawer : public SpreadsheetDrawer { 0, nullptr); } - else if (std::holds_alternative<float>(cell_value.value)) { - const float value = *std::get_if<float>(&cell_value.value); + else if (const float *value = std::any_cast<float>(&cell_value.value)) { std::stringstream ss; - ss << std::fixed << std::setprecision(3) << value; + ss << std::fixed << std::setprecision(3) << *value; const std::string value_str = ss.str(); uiDefIconTextBut(params.block, UI_BTYPE_LABEL, @@ -158,9 +156,8 @@ class ColumnLayoutDrawer : public SpreadsheetDrawer { 0, nullptr); } - else if (std::holds_alternative<bool>(cell_value.value)) { - const bool value = *std::get_if<bool>(&cell_value.value); - const int icon = value ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT; + else if (const bool *value = std::any_cast<bool>(&cell_value.value)) { + const int icon = (*value) ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT; uiDefIconTextBut(params.block, UI_BTYPE_LABEL, 0, @@ -177,13 +174,12 @@ class ColumnLayoutDrawer : public SpreadsheetDrawer { 0, nullptr); } - else if (std::holds_alternative<ObjectCellValue>(cell_value.value)) { - const ObjectCellValue value = *std::get_if<ObjectCellValue>(&cell_value.value); + else if (const ObjectCellValue *value = std::any_cast<ObjectCellValue>(&cell_value.value)) { uiDefIconTextBut(params.block, UI_BTYPE_LABEL, 0, ICON_OBJECT_DATA, - reinterpret_cast<const ID *const>(value.object)->name + 2, + reinterpret_cast<const ID *const>(value->object)->name + 2, params.xmin, params.ymin, params.width, @@ -195,13 +191,13 @@ class ColumnLayoutDrawer : public SpreadsheetDrawer { 0, nullptr); } - else if (std::holds_alternative<CollectionCellValue>(cell_value.value)) { - const CollectionCellValue value = *std::get_if<CollectionCellValue>(&cell_value.value); + else if (const CollectionCellValue *value = std::any_cast<CollectionCellValue>( + &cell_value.value)) { uiDefIconTextBut(params.block, UI_BTYPE_LABEL, 0, ICON_OUTLINER_COLLECTION, - reinterpret_cast<const ID *const>(value.collection)->name + 2, + reinterpret_cast<const ID *const>(value->collection)->name + 2, params.xmin, params.ymin, params.width, diff --git a/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.hh b/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.hh index a01e251d764..88f0a274922 100644 --- a/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.hh +++ b/source/blender/editors/space_spreadsheet/spreadsheet_column_layout.hh @@ -16,7 +16,7 @@ #pragma once -#include <variant> +#include <any> #include "spreadsheet_draw.hh" @@ -39,12 +39,9 @@ struct CollectionCellValue { */ class CellValue { public: - /* The implementation just uses a `std::variant` for simplicity. It can be encapsulated better, + /* The implementation just uses a `std::any` for simplicity. It can be encapsulated better, * but it's not really worth the complixity for now. */ - using VariantType = - std::variant<std::monostate, int, float, bool, ObjectCellValue, CollectionCellValue>; - - VariantType value; + std::any value; }; /** _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs