If you have a method and you want to give the compiler a hint that it is a good idea to inline it, you currently have two solutions. The first one is to define the methods when you declare your class:
class Vector {
private:
double* data_;
double* size_;
double* capacity_;
public:
double& operator[](int k) {
return data_[k];
}
...
}
As this method might reduce readability, another solution is to use the inline
keyword and define the method out of class:
class Vector {
private:
double* data_;
double* size_;
double* capacity_;
public:
inline double& operator[](int k);
...
}
double& Vector::operator[](int k) {
return data_[k];
}
This makes the code more readable (at least I prefer it). Reading my STL implementation, I found that they use a mix of the two. Some methods (those which I think should really be inlined) are defined in the class, and others are defined out of class with the inline keyword. The file also begins with a commented declaration of the class.
So my question is the following. Do current compilers (I am thinking of GCC, Clang, Intel, and Visual Studio) are more likely to inline a member function that is declared inside the class than a member function declared out of class with the inline keyword?
Remark: This question is not a duplicate of When should I write the keyword 'inline' for a function/method? as my question is about compiler implementations. Do these two ways of saying that you want those functions to be inlined are equivalent. The way the STL is written suggests that they are not.