Skip to content
This repository was archived by the owner on Mar 22, 2021. It is now read-only.
This repository was archived by the owner on Mar 22, 2021. It is now read-only.

Add support for templated MxArray conversions #25

@dnmiller

Description

@dnmiller

Edit: Updating with new request, as my original code was incorrect.

I'd like to first say thank you for this library. It's very useful.

I was trying to extend MxArray with conversions to/from std::array and was running into problems with deducing the type/size of the array. If I make the from function not a member of MxArray, then I can implement the conversion:

    template <typename T, size_t N>
    mxArray* from(const std::array<T, N>& value) {
        MxArray result(MxArray::Numeric<T>(N, 1));
        result.set(value);
        return result.release();
    }

If I change from to MxArray::from, then it won't compile.

A similar attempt to implement the to function does not compile in either case:

    template <typename T, size_t N>
    void MxArray::to(const mxArray* array, std::array<T, N>* value) {
        MxArray input(array);
        for (auto i = 0u; i < N; ++i) {
            (*value)[i] = input.at<T>(i);
        }
    }

This would be a great feature to have for extending to templated data types.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions