I am implementing something very similar to std::vector , but using an array on the stack instead of allocating memory.
d-tor calls a function that uses SFINAE.
- If
value_type is a POD, the function has an empty body. - If
value_type is a normal class, such a std::string , the function has a body and correctly destroys all the data.
Now I want to use this new std::vector as constexpr . However, even c-tor is declared constexpr , the code does not compile because the class has a nontrivial d-tor.
Here is a small piece of code:
template<typename T, std::size_t SIZE> class SmallVector{ constexpr SmallVector() = default; ~SmallVector(){ destructAll_<value_type>(); }
Is there anything I can do to make the class constexpr if value_type is a POD and retains functionality for data types other than POD.
(Not at the same time, of course)
source share