I have constexpr object constructor with constexpr methods.
// My SparseArray implementation
#include <cstdint>
#include <iostream>
#include <utility>
template<typename T, uint64_t size>
class SparseArray
{
public:
using ElementType = T;
template<typename... Args>
constexpr SparseArray(Args&&... args)
: values{args...} {
std::cout << "Args ctor." << '\n';
}
template<uint8_t Index>
constexpr ElementType get() const {
// some logic
return T();
}
constexpr auto someMethod() {
get<0>(); // <--------- works fine
auto seq = std::integer_sequence<ElementType, 0>{}; // <--------- works fine
auto seq2 = std::integer_sequence<ElementType, get<0>()>{}; // <-- error
}
ElementType values[size];
};
int main ()
{
SparseArray<int, 3> array(1, 2, 3);
array.someMethod();
return 0 ;
}
But I really need to use method in such compile-time context. I'm going to sum two constexpr objects in compile-time, so I need to get data of both thanks to get method.
=======Edited=====
After @chris answer I understood that I missed one thing. Actually get method looks like this:
template<uint8_t Index>
constexpr ElementType get() const {
if(/*some logic*/)
return values[/*some logic*/];
else
return T();
}
So, the code deals with data member of the object.