feat: Multiple inputs to vector-type parameters - #2189
Conversation
| requires(std::is_pointer_v<DataClass>) | ||
| : ParameterBase(parent, name, description, std::type_index(typeid(DataClass))), data_(localPointer_), default_(nullptr), | ||
| dataGetter_([&]() { return targetData.has_value() ? &targetData.value() : nullptr; }), | ||
| dataSetter_([](const DataClass &value) { return false; }) |
There was a problem hiding this comment.
Is this just a temp value until we fix it at a later date or am I missing a reason why we can't have a setter here? Somethin along the lines of:
if (value == nullptr && targetData.has_value())
{
targetData = {};
return true;
}
if (value != nullptr && (!targetData.has_value() || *targetData != value))
{
targetData = value;
return true;
}
return false;There was a problem hiding this comment.
One of the reasons against all this requires usage is the fact that it can obfuscate the intent of things a bit, or at least require you to balance the context with another four overloads at the same time! Here the source data object is a std::optional and basically constitutes a read-only Parameter, hence the setter returns a hard fail.
1590869 to
ebf177a
Compare
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.
| Benchmark suite | Current: 3d4ca4a | Previous: 3f79d38 | Ratio |
|---|---|---|---|
BM_Box_MinimumImage<CubicBox> |
13.572743355106727 ns/iter |
6.235206516096226 ns/iter |
2.18 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @disorderedmaterials/dissolve-devs
Co-authored-by: Tristan Youngs <trisyoungs@googlemail.com>
Co-authored-by: Tristan Youngs <trisyoungs@googlemail.com>
This PR implements handling of
std::vectors inParameters, allowing them to be set via either another vector or to be constructed piecewise from multiple single data item inputs. The nice side effect is that there is now a singleParameter<T>class with no derived specialisations (save forFunction1DWrapperwhich could also be accounted for but would pollute the class a little bit, plus it's slated for addressing at a later stage).I'll be honest - I went around the houses on this one! No amount of template mangling, overloading, or C++20 sugar would ultimately allow me to follow my initial route which was to move to a
Parameter<DataClass,StorageClass>where the storage type was explicitly known and could thus be accounted for withconstexprconditionals, but it turns out that this is (probably) impossible as one or the other template classes is "lost" when you work from functions inParameterBase(which we necessarily do). However, the C++20requireskeyword came to the rescue, and the end result is something not too far from what I had originally tried to create.The base
upcast()function is gone and theParameterBase<T>::set()andget()functions are now very type explicit, e.g. passing anintor adoublewhen setting aNumberwill not work. However, we only do this in the unit tests so no real biggie.