On Fri, Jan 30, 2026 at 6:44 PM Even Rouault <[email protected]>
wrote:

> Andrew,
>
> we regularly do slightly forward incompatible changes in the C++ API, and
> they are documented in
> https://gdal.org/en/latest/user/migration_guide.html .
>
> That change has the advantage of avoiding potential usage errors, in
> particular erroneous use of CSLDestroy() on the return value, which was
> possible when we returned "char **".   That way, you can distinguish that
> GetMetadata() return doesn't need to be freed, whereas methods such as
> GDALDataset::GetMetadataDomainList() or GetFileList() that return a
> "char**" do need to have their return value CSLDestroy()'ed after use
>
I guess my feeling is that if the interface has been good enough for 30
years than it doesn't really need to be changed. Programmers need to take
responsibility to use a library properly.

You could leave the current interface in place and add functions to provide
better safety and an interface more expected by C++ programmers. For
example:

    std::vector<std::string> Metadata(const std::string& domain = "")
    {
        std::vector<std::string> v;
        char **p = GetMetadata(domain.c_str());
        while (p)
            v.emplace_back(*p++);
        return v;
    }

    std::vector<std::string_view> MetadataView(const std::string& domain =
"")
    {
        std::vector<std::string_view> v;
        char **p = GetMetadata(domain.c_str());
        while (p)
            v.emplace_back(*p++);
        return v;
    }

These functions can be made const without too much trouble as well.

-- 
Andrew Bell
[email protected]
_______________________________________________
gdal-dev mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to