Skip to content

Using aggregate types with StateValue broke #594

@chrhaase

Description

@chrhaase

I have code like this in my project and on the master branch this works well.
Just checked out next and now it won't compile.

Do you have an idea why and how it can be fixed?

struct AggregateType
{
    juce::String a;
    juce::String b;

    friend bool operator== (const AggregateType& lhs, const AggregateType& rhs) { return lhs.a == rhs.a
                                                                                         && lhs.b == rhs.b; }
    friend bool operator!= (const AggregateType& lhs, const AggregateType& rhs) { return ! (lhs == rhs); }
};

chowdsp::StateValue<AggregateType> aggregate;

Here's the error message from AppleClang:

In file included from /Users/chrhaase/dev/ChowDSP/chowdsp_utils/tests/plugin_tests/chowdsp_plugin_state_test/NonParamTest.cpp:2:
In file included from /Users/chrhaase/dev/ChowDSP/chowdsp_utils/modules/plugin/chowdsp_plugin_state/chowdsp_plugin_state.h:36:
/Users/chrhaase/dev/ChowDSP/chowdsp_utils/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_StateValue.h:76:16: error: no viable conversion from returned value of type 'element_type' (aka 'AggregateType') to function return type 'nlohmann::json' (aka 'basic_json<>')
   76 |         return get();
      |                ^~~~~
/Users/chrhaase/dev/ChowDSP/chowdsp_utils/tests/plugin_tests/chowdsp_plugin_state_test/NonParamTest.cpp:25:44: note: in instantiation of member function 'chowdsp::StateValue<AggregateType>::serialize_json' requested here
   25 |         chowdsp::StateValue<AggregateType> aggregate_val { "aggregate", { "foo", "bar" } };
      |                                            ^
/Users/chrhaase/dev/ChowDSP/chowdsp_utils/modules/common/chowdsp_json/third_party/nlohmann/json.hpp:19879:5: note: candidate constructor not viable: no known conversion from 'element_type' (aka 'AggregateType') to 'const value_t' (aka 'const nlohmann::detail::value_t') for 1st argument
 19879 |     basic_json(const value_t v)
       |     ^          ~~~~~~~~~~~~~~~
/Users/chrhaase/dev/ChowDSP/chowdsp_utils/modules/common/chowdsp_json/third_party/nlohmann/json.hpp:19887:5: note: candidate constructor not viable: no known conversion from 'element_type' (aka 'AggregateType') to 'std::nullptr_t' for 1st argument
 19887 |     basic_json(std::nullptr_t = nullptr) noexcept // NOLINT(bugprone-exception-escape)
       |     ^          ~~~~~~~~~~~~~~~~~~~~~~~~
/Users/chrhaase/dev/ChowDSP/chowdsp_utils/modules/common/chowdsp_json/third_party/nlohmann/json.hpp:19966:5: note: candidate constructor not viable: no known conversion from 'element_type' (aka 'AggregateType') to 'initializer_list_t' (aka 'initializer_list<detail::json_ref<basic_json<std::map, std::vector, string, bool, long long, unsigned long long, double, std::allocator, nlohmann::adl_serializer, vector<unsigned char, allocator<unsigned char>>>>>') for 1st argument
 19966 |     basic_json(initializer_list_t init,
       |     ^          ~~~~~~~~~~~~~~~~~~~~~~~
/Users/chrhaase/dev/ChowDSP/chowdsp_utils/modules/common/chowdsp_json/third_party/nlohmann/json.hpp:20208:5: note: candidate constructor not viable: no known conversion from 'element_type' (aka 'AggregateType') to 'const basic_json<> &' for 1st argument
 20208 |     basic_json(const basic_json& other)
       |     ^          ~~~~~~~~~~~~~~~~~~~~~~~
/Users/chrhaase/dev/ChowDSP/chowdsp_utils/modules/common/chowdsp_json/third_party/nlohmann/json.hpp:20276:5: note: candidate constructor not viable: no known conversion from 'element_type' (aka 'AggregateType') to 'basic_json<> &&' for 1st argument
 20276 |     basic_json(basic_json&& other) noexcept
       |     ^          ~~~~~~~~~~~~~~~~~~
/Users/chrhaase/dev/ChowDSP/chowdsp_utils/modules/common/chowdsp_json/third_party/nlohmann/json.hpp:19899:5: note: candidate template ignored: requirement 'detail::is_compatible_type<nlohmann::basic_json<std::map, std::vector, std::string, bool, long long, unsigned long long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char>>>, AggregateType>::value' was not satisfied [with CompatibleType = element_type, U = detail::uncvref_t<element_type>]
 19899 |     basic_json(CompatibleType && val) noexcept(noexcept( // NOLINT(bugprone-forwarding-reference-overload,bugprone-exception-escape)
       |     ^
/Users/chrhaase/dev/ChowDSP/chowdsp_utils/modules/common/chowdsp_json/third_party/nlohmann/json.hpp:19913:5: note: candidate template ignored: requirement 'detail::is_basic_json<AggregateType>::value' was not satisfied [with BasicJsonType = element_type]
 19913 |     basic_json(const BasicJsonType& val)
       |     ^
/Users/chrhaase/dev/ChowDSP/chowdsp_utils/modules/common/chowdsp_json/third_party/nlohmann/json.hpp:20204:5: note: candidate template ignored: substitution failure [with JsonRef = element_type]: no type named 'value_type' in 'AggregateType'
 20203 |                                  std::is_same<typename JsonRef::value_type, basic_json>>::value, int> = 0 >
       |                                                                 ~~~~~~~~~~
 20204 |     basic_json(const JsonRef& ref) : basic_json(ref.moved_or_copied()) {}
       |     ^
In file included from /Users/chrhaase/dev/ChowDSP/chowdsp_utils/tests/plugin_tests/chowdsp_plugin_state_test/NonParamTest.cpp:2:
In file included from /Users/chrhaase/dev/ChowDSP/chowdsp_utils/modules/plugin/chowdsp_plugin_state/chowdsp_plugin_state.h:36:
/Users/chrhaase/dev/ChowDSP/chowdsp_utils/modules/plugin/chowdsp_plugin_state/Backend/chowdsp_StateValue.h:82:23: error: no matching member function for call to 'get'
   82 |         set (deserial.get<element_type>());
      |              ~~~~~~~~~^~~~~~~~~~~~~~~~~
/Users/chrhaase/dev/ChowDSP/chowdsp_utils/tests/plugin_tests/chowdsp_plugin_state_test/NonParamTest.cpp:25:44: note: in instantiation of member function 'chowdsp::StateValue<AggregateType>::deserialize_json' requested here
   25 |         chowdsp::StateValue<AggregateType> aggregate_val { "aggregate", { "foo", "bar" } };
      |                                            ^
/Users/chrhaase/dev/ChowDSP/chowdsp_utils/modules/common/chowdsp_json/third_party/nlohmann/json.hpp:20805:10: note: candidate template ignored: substitution failure [with ValueTypeCV = element_type, ValueType = detail::uncvref_t<element_type>]: no matching member function for call to 'get_impl'
 20805 |     auto get() const noexcept(
       |          ^
 20806 |     noexcept(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {})))
 20807 |     -> decltype(std::declval<const basic_json_t&>().template get_impl<ValueType>(detail::priority_tag<4> {}))
       |                                                              ~~~~~~~~
/Users/chrhaase/dev/ChowDSP/chowdsp_utils/modules/common/chowdsp_json/third_party/nlohmann/json.hpp:20846:10: note: candidate template ignored: substitution failure [with PointerType = element_type]: no matching member function for call to 'get_ptr'
 20846 |     auto get() noexcept -> decltype(std::declval<basic_json_t&>().template get_ptr<PointerType>())
       |          ^                                                                 ~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions