What do you recommend to do in such situation, when for instance you need to use functions from <algorithm>
in both header file and source file?
example.hpp:
#include <algorithm>
#include <vector>
class Example
{
public:
void definitionInHeader() { std::fill(m_values.begin(), m_values.end(), 10); }
void definitionInSource();
private:
std::vector<int> m_values(10);
}
example.cpp:
#include "example.hpp"
void Example::definitionInSource()
{
//Code from <algorithm> is available here due to inclusion of example.hpp
std::vector<int> integers{ 1, 2, 3, 4, 5 };
auto print = [](int i){ std::cout << i << std::endl };
std::for_each(integers.begin(), integers.end(), print);
}
Do you recommend to explicitly include in source file as well or maybe include only in header file? In my opinion, additional inclusion cost is meaningless, but if someone in the future will refactor such code and remove from header file, source file will have to be edited as well. On the other hand, include section in source file may get a bit long. What do you recommend?