Skip to content

Cannot implicitly convert between a subclass of std::vector<T*> and tcb::span<const T* const> #56

@matthew-wozniczka

Description

@matthew-wozniczka

I have an AutoVector<T> template class in our codebase which inherits publicly from std::vector<T*> and handles ownership (created before the days of C++11).

I've noticed that I get compiler errors when I try to have an instance of this type implicitly convert to the associated span type, for example, something like

namespace Simba { namespace Support { class SqlTypeMetadata; } }

void UseMeta(simba_thirdparty_tcb::span<const Foo* const> meta);

void bar()
{
    AutoVector<Foo> meta(GetMeta());
    UseMeta(meta); // error C2440: 'return': cannot convert from 'Simba::Support::AutoVector<Simba::Support::SqlTypeMetadata>' to 'simba_thirdparty_tcb::span<const Simba::Support::SqlTypeMetadata *const ,18446744073709551615>'
    // UseMeta({ meta.data(), meta.size() }); // This works
}

similar code works fine when using std::vector<T*> directly. Looking at the C++20 std::span documentation, this should work as long as the AutoVector<T> type models the Range concept, and I think if std::vector does, so should a subclass (that doesn't explicitly delete any member functions)?

I'm having the problem in Visual Studio 2019, haven't tried any other compilers/platforms yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions