Hi All,
I’m getting an assert in this constructor (everything is invalid, type, value, valueToCopy)
var::var (const var& valueToCopy) : type (valueToCopy.type)
{
type->createCopy (value, valueToCopy.value);
}
when attempting to create a value tree using a lambda to create an initializer list for the properties, like this:
//1- invalid value tree example with lambda initializer list
auto getInitializerListFromLambda = []()-> std::initializer_list<juce::NamedValueSet::NamedValue>
{
return
{
{ "id", {.3} },
{"value", {0.5}}
};
};
ValueTree invalidTree = {"NotWorking", getInitializerListFromLambda()};
By comparison, using a local initializer list works:
//2- valid value tree example with local initializer list
std::initializer_list<juce::NamedValueSet::NamedValue> localList =
{
{ "id", var(.3) },
{"value", var(0.5)}
};
auto validTree = ValueTree(VoodooIds::effectStateId, localList);
Googling this tells me that the problem may be that the content of the initializer list may not persist after the lambda scope… but then why is this working fine?
//3- valid vector example with initializer list created in lambda
auto foo = []() -> std::initializer_list<int> { return {1, 2}; };
std::vector<int> bar{foo()};
for (int x : bar) { std::cout << x << " "; };
I have tried a number of things, such as using explicit NamedValueSet
constructors, returning a pointer to a dynamically created initializer list in the lambda, different types of constructors for the vars… nothing works. Could it be related to the std::move
in here?
ValueTree::ValueTree (const Identifier& type,
std::initializer_list<NamedValueSet::NamedValue> properties,
std::initializer_list<ValueTree> subTrees)
: ValueTree (type)
{
object->properties = NamedValueSet (std::move (properties));
for (auto& tree : subTrees)
addChild (tree, -1, nullptr);
}