I have currently implemented a library using the pImpl idiom as such (just an example);
// library.h
class lib_public_type
{
class impl;
std::unique_ptr<impl> impl__;
public:
void libTypeFunction();
}
// library.cpp
#include "library.h"
class lib_public_type::impl
{
private:
std::string libVar1;
void libPrivateFunction1()
{
...
}
void libPrivateFunction2()
{
...
}
}
lib_public_type::libTypeFunction()
{
libPrivateFunction1();
libPrivateFunction2();
}
Now I would like to remove as much unneeded information from the header file as possible for another project using a built version of the library. I was wondering if there is a better way of removing the internals from the header of lib_public_type
without resorting to maintaining two separate headers?
Would it be possible to do something like;
// library.h
#ifndef PROVIDES_IMPL
// define as empty string if not already defined
#define PROVIDES_IMPL
#endif
class lib_public_type
{
PROVIDES_IMPL
public:
void libTypeFunction();
}
// library.cpp
#define PROVIDES_IMPL class impl;\
std::unique_ptr<impl> impl__;
#include "library.h"
...
Or would this have unwanted consequences for the project using the library?