arximboldi / immer

Postmodern immutable and persistent data structures for C++ — value semantics at scale
https://sinusoid.es/immer
Boost Software License 1.0
2.51k stars 184 forks source link

error when erasing an element from a immer::flex_vector<std::variant/optional/any> #45

Closed deiflou closed 6 years ago

deiflou commented 6 years ago

If I use a std::variant or std::optional or std::any with an immer::flex_vector like in this code:

#include <immer/flex_vector.hpp>
#include <variant>
// #include <optional>
// #include <any>

int main()
{
    using Vector = immer::flex_vector<std::variant<int, double>>;
    // using Vector = immer::flex_vector<std::optional<int>>;
    // using Vector = immer::flex_vector<std::any>;

    Vector v{1, 2, 3, 4};
    Vector v2 = v.erase(2);

    return 0;
}

I get the following error when trying to erase an element:

error: call of overloaded 'uninitialized_move(std::variant<int, double>*, std::variant<int, double>*, std::variant<int, double>*)' is ambiguous

Full output:

[build] Starting build
[proc] Executing command: d:\msys64\mingw64\bin\cmake.EXE --build d:/projects/build/test/immer_test/debug --config Debug --target all -- -j 6
[build] Scanning dependencies of target immer_test
[build] [ 50%] Building CXX object CMakeFiles/immer_test.dir/test02.cpp.obj
[build] In file included from D:/projects/install/debug/include/immer/flex_vector.hpp:23:0,
[build]                  from D:\projects\src\test\immer_test\test02.cpp:1:
[build] D:/projects/install/debug/include/immer/detail/rbts/rrbtree.hpp: In instantiation of 'void immer::detail::rbts::concat_mut_lr_l(immer::detail::rbts::rrbtree<std::variant<int, double>, immer::memory_policy<immer::free_list_heap_policy<immer::cpp_heap>, immer::refcount_policy>, 5, 4>&, immer::detail::rbts::rrbtree<std::variant<int, double>, immer::memory_policy<immer::free_list_heap_policy<immer::cpp_heap>, immer::refcount_policy>, 5, 4>::edit_t, immer::detail::rbts::rrbtree<std::variant<int, double>, immer::memory_policy<immer::free_list_heap_policy<immer::cpp_heap>, immer::refcount_policy>, 5, 4>&, immer::detail::rbts::rrbtree<std::variant<int, double>, immer::memory_policy<immer::free_list_heap_policy<immer::cpp_heap>, immer::refcount_policy>, 5, 4>::edit_t)':
[build] D:/projects/install/debug/include/immer/flex_vector.hpp:505:22:   required from 'static immer::flex_vector<T, MemoryPolicy, B, BL>&& immer::flex_vector<T, MemoryPolicy, B, BL>::concat_move(std::true_type, immer::flex_vector<T, MemoryPolicy, B, BL>&&, immer::flex_vector<T, MemoryPolicy, B, BL>&&) [with T = std::variant<int, double>; MemoryPolicy = immer::memory_policy<immer::free_list_heap_policy<immer::cpp_heap>, immer::refcount_policy>; unsigned int B = 5; unsigned int BL = 4; std::true_type = std::integral_constant<bool, true>]'
[build] D:/projects/install/debug/include/immer/flex_vector.hpp:371:25:   required from 'decltype(auto) immer::operator+(immer::flex_vector<std::variant<int, double> >&&, immer::flex_vector<std::variant<int, double> >&&)'
[build] D:/projects/install/debug/include/immer/flex_vector.hpp:424:24:   required from 'immer::flex_vector<T, MemoryPolicy, B, BL> immer::flex_vector<T, MemoryPolicy, B, BL>::erase(immer::flex_vector<T, MemoryPolicy, B, BL>::size_type) const & [with T = std::variant<int, double>; MemoryPolicy = immer::memory_policy<immer::free_list_heap_policy<immer::cpp_heap>, immer::refcount_policy>; unsigned int B = 5; unsigned int BL = 4; immer::flex_vector<T, MemoryPolicy, B, BL>::size_type = long long unsigned int]'
[build] D:\projects\src\test\immer_test\test02.cpp:14:26:   required from here
[build] D:/projects/install/debug/include/immer/detail/rbts/rrbtree.hpp:962:39: error: call of overloaded 'uninitialized_move(std::variant<int, double>*, std::variant<int, double>*, std::variant<int, double>*)' is ambiguous
[build]                      uninitialized_move(r.tail->leaf(),
[build]                      ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
[build]                                         r.tail->leaf() + r.size,
[build]                                         ~~~~~~~~~~~~~~~~~~~~~~~~
[build]                                         l.tail->leaf() + tail_size);
[build]                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
[build] In file included from D:/projects/install/debug/include/immer/detail/rbts/node.hpp:25:0,
[build]                  from D:/projects/install/debug/include/immer/detail/rbts/rrbtree.hpp:24,
[build]                  from D:/projects/install/debug/include/immer/flex_vector.hpp:23,
[build]                  from D:\projects\src\test\immer_test\test02.cpp:1:
[build] D:/projects/install/debug/include/immer/detail/util.hpp:43:6: note: candidate: auto immer::detail::uninitialized_move(Iter1, Iter1, Iter2) [with Iter1 = std::variant<int, double>*; Iter2 = std::variant<int, double>*]
[build]  auto uninitialized_move(Iter1 in1, Iter1 in2, Iter2 out)
[build]       ^~~~~~~~~~~~~~~~~~
[build] In file included from d:/msys64/mingw64/include/c++/7.3.0/memory:65:0,
[build]                  from D:/projects/install/debug/include/immer/detail/util.hpp:28,
[build]                  from D:/projects/install/debug/include/immer/detail/rbts/node.hpp:25,
[build]                  from D:/projects/install/debug/include/immer/detail/rbts/rrbtree.hpp:24,
[build]                  from D:/projects/install/debug/include/immer/flex_vector.hpp:23,
[build]                  from D:\projects\src\test\immer_test\test02.cpp:1:
[build] d:/msys64/mingw64/include/c++/7.3.0/bits/stl_uninitialized.h:862:5: note: candidate: _ForwardIterator std::uninitialized_move(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::variant<int, double>*; _ForwardIterator = std::variant<int, double>*]
[build]      uninitialized_move(_InputIterator __first, _InputIterator __last,
[build]      ^~~~~~~~~~~~~~~~~~
[build] In file included from D:/projects/install/debug/include/immer/flex_vector.hpp:23:0,
[build]                  from D:\projects\src\test\immer_test\test02.cpp:1:
[build] D:/projects/install/debug/include/immer/detail/rbts/rrbtree.hpp:975:39: error: call of overloaded 'uninitialized_move(std::variant<int, double>*, std::variant<int, double>*, std::variant<int, double>*)' is ambiguous
[build]                      uninitialized_move(r.tail->leaf(),
[build]                      ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
[build]                                         r.tail->leaf() + remaining,
[build]                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
[build]                                         l.tail->leaf() + tail_size);
[build]                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
[build] In file included from D:/projects/install/debug/include/immer/detail/rbts/node.hpp:25:0,
[build]                  from D:/projects/install/debug/include/immer/detail/rbts/rrbtree.hpp:24,
[build]                  from D:/projects/install/debug/include/immer/flex_vector.hpp:23,
[build]                  from D:\projects\src\test\immer_test\test02.cpp:1:
[build] D:/projects/install/debug/include/immer/detail/util.hpp:43:6: note: candidate: auto immer::detail::uninitialized_move(Iter1, Iter1, Iter2) [with Iter1 = std::variant<int, double>*; Iter2 = std::variant<int, double>*]
[build]  auto uninitialized_move(Iter1 in1, Iter1 in2, Iter2 out)
[build]       ^~~~~~~~~~~~~~~~~~
[build] In file included from d:/msys64/mingw64/include/c++/7.3.0/memory:65:0,
[build]                  from D:/projects/install/debug/include/immer/detail/util.hpp:28,
[build]                  from D:/projects/install/debug/include/immer/detail/rbts/node.hpp:25,
[build]                  from D:/projects/install/debug/include/immer/detail/rbts/rrbtree.hpp:24,
[build]                  from D:/projects/install/debug/include/immer/flex_vector.hpp:23,
[build]                  from D:\projects\src\test\immer_test\test02.cpp:1:
[build] d:/msys64/mingw64/include/c++/7.3.0/bits/stl_uninitialized.h:862:5: note: candidate: _ForwardIterator std::uninitialized_move(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = std::variant<int, double>*; _ForwardIterator = std::variant<int, double>*]
[build]      uninitialized_move(_InputIterator __first, _InputIterator __last,
[build]      ^~~~~~~~~~~~~~~~~~
[build] mingw32-make.exe[2]: *** [CMakeFiles\immer_test.dir\build.make:63: CMakeFiles/immer_test.dir/test02.cpp.obj] Error 1
[build] mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:67: CMakeFiles/immer_test.dir/all] Error 2
[build] mingw32-make.exe: *** [Makefile:83: all] Error 2
[build] Build finished with exit code 2
arximboldi commented 6 years ago

Thanks for the report. Can you tell me which compiler are you using (incl version and platform)? Thanks!

deiflou commented 6 years ago

Sorry, I forgot to write that info in the previous message.

Compiler: GCC 7.3.0, under MSYS2/MinGW64 Platform: Windows 10, 64 bits

arximboldi commented 6 years ago

Ohhh, I see the problem now. I will patch it over the weekend. Thanks!

arximboldi commented 6 years ago

A fix is on the way. Thanks again for reporting this!

To ensure responsive support in the future, if you are using Immer in a commercial project, please consider sponsoring the project (via Patreon or just drop me an email for other agreements smile )

deiflou commented 6 years ago

Thanks. Well, I'm not a programmer, I just program for hobby. I'm actually an artist and what got me interested in programming is basically the stuff related to image processing and graphics in general. I'm unemployed currently but I'll try to contribute something. I've also heard that tipeee is a better donation platform for people in europe (I'm from Spain). Like I said, I'm an artist (painter/illustrator), so if you need some help in that area sometime I'm happy to help (some of my work: http://deiflou.tumblr.com/).

arximboldi commented 6 years ago

Aha! Thanks for the tips :) I'm from Spain too (from Huelva) but I've been living 6 years in Berlin already. I find it amazing that as an artist you are into advanced programming topics like immutable data-structures in C++. I used to paint too when I was younger but over the years that has become a very secondary hobbie. Your porfolio looks amazing indeed! Once again: thanks for all the feedback and thorough bug reports! Hasta pronto :)