Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-03-21 14:33:18 +0300
committerJacques Lucke <jacques@blender.org>2021-03-21 14:33:18 +0300
commitd546905f1dad4b0c1185c29742851f748710bd93 (patch)
treec7e4485b3af287434e5a684e6af0983f5453ccb4
parent90959c23728fe569d16ce0a962e841e5accd9e51 (diff)
replace std::variant with std::anytemp-any-instead-of-variant
-rw-r--r--source/blender/editors/space_spreadsheet/spreadsheet_column_layout.cc26
-rw-r--r--source/blender/editors/space_spreadsheet/spreadsheet_column_layout.hh9
2 files changed, 14 insertions, 21 deletions
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;
};
/**