boost-ext / te

C++17 Run-time Polymorphism (Type Erasure) library
463 stars 39 forks source link

Cannot reserve, resize nor emplace_back in std::vector<te::poly<Type>> #9

Closed ArekPiekarz closed 6 years ago

ArekPiekarz commented 6 years ago

It's not possible to change internal or external size of std::vector that stores te::poly objects, nor emplace_back objects into it.

Example with reserving space in the vector:

#include "external/te/include/te.hpp"
#include <vector>

struct Drawable
{
    auto draw() -> REQUIRES(void, draw)
};

int main()
{
    std::vector<te::poly<Drawable>> drawables;
    drawables.reserve(1);
}

Its compilation fails with:

/usr/include/c++/7/type_traits:1162: error: invalid use of incomplete type ‘struct std::is_constructible<te::v1::poly<Drawable>, te::v1::poly<Drawable, te::v1::dynamic_storage, te::v1::static_vtable>&&>’
     struct __is_move_constructible_impl<_Tp, true>
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When we change reserve to resize, we get the same error and additionally this one:

/usr/include/c++/7/bits/stl_construct.h:75: error: no matching function for call to ‘te::v1::poly<Drawable>::poly()’
     { ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

When we change the code to test emplace_back with a potentially drawable object:

struct Circle
{
    void draw() {}
};

int main()
{
    std::vector<te::poly<Drawable>> drawables;
    drawables.emplace_back(Circle{});
}

we get the same error as in the reserve case.

Environment OS: Ubuntu 17.10 x64 Compiler: GCC 7.2 x64

ArekPiekarz commented 6 years ago

Thanks! resize(x) on vector still doesn't work, is it by design to not have an empty object? If so, it's worth noting it at least here.

The current compilation error is:

/usr/include/c++/7/bits/stl_construct.h:75: error: no matching function for call to ‘te::v1::poly<Drawable>::poly()’
     { ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~