Is there a way to compile the method or not, depending on the template argument? I am trying to create a Coordinate class that can handle 2, 3 or more dimensions. I want to provide acces methods like x() , y() and z() , but I would like the z() method to be available only if the size is greater than 3. At the moment (as you can see below) I use a static_assert to prevent the use of z() for coordinates of dimension 2.
template<typename DataType, int Dimension> class Coord { private: std::array<DataType, Dimension> _data; public:
What I would like to do is hide the existence of z() for dimension 2, so this
Coord<int, 2> ci2(0,0); ci2.z() = 3;
does not compile without using static_assert. I saw a lot of questions around std :: enable_if, but as I understand it, it is used to enable or disable certain overloads.
Question: is there a way to make the method available or not depending on the compile-time argument?
source share