gul-cpp / gul14

General Utility Library for C++14
https://gul14.info/
GNU Lesser General Public License v2.1
2 stars 1 forks source link

SmallVector can not take const stuff? #57

Closed Finii closed 10 months ago

Finii commented 10 months ago
auto dirs = gul14::SmallVector<std::string const, 2>{ dir1, dir2 };
../subprojects/libgul14/include/gul14/SmallVector.h:1254:23: error: invalid ‘static_cast’ from type ‘const std::__cxx11::basic_string<char>*’ to type ‘void*’
 1254 |                 ::new(static_cast<void*>(data_ptr)) ValueType{ *it };
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Finii commented 10 months ago

I guess just a remove_cv_t is missing @alt-graph

alt-graph commented 10 months ago

A std::vector cannot contain const items:

/opt/wandbox/gcc-13.2.0/include/c++/13.2.0/bits/stl_vector.h: In instantiation of 'class std::vector<const int>':
prog.cc:10:28:   required from here
/opt/wandbox/gcc-13.2.0/include/c++/13.2.0/bits/stl_vector.h:437:66: error: static assertion failed: std::vector must have a non-const, non-volatile value_type

... so I think our SmallVector should follow suit. But maybe we should add a nice static_assert like above?

Finii commented 10 months ago

Waahhh :sob:

Man darf nie vernuenftige Sprachen benutzen und dann wieder zu C++ wechseln

Yes, would be nice, maybe. I would close this Issue now. Sigh.

What I wanted to have was a SmallVector<std::string const&, n> but that is already impossible because it can not work with refs. Passing multiple strings in a lightweight manner seems ... hard. Now I use gul::string_view, but THAT is missing all the nice conversion ops :unamused: I want to use std::string_view; I really hate this gul thing in c++17 code.