C ++ library :. hpp + .inl (separate definitions and declarations) vs .hpp only (intraclass body code)

I am rewriting my own native Windows C ++ library (a constant effort since 2002) with a public release. Over the past 10 years, I have been the sole beneficiary of these 150+ KLOCs, and I feel that others can find good use for this.

Currently, the entire library is pretty boilerplate and just a title. This means that all the code is in the body of the classes. It is not very easy to manage, but it is normal.

I am very tempted to read a few tutorials on coding C ++ libraries to break it down into .hpp + .inl . Experimentally done for several classes, and this improves readability and makes it easier for others to engage. I know where everything is at any moment. But other users may need a brief overview of class declarations ... and definition only if necessary (debugging).

Question :
What are the pros and cons of separating member definitions from a class definition for a class template? There is a common practice.

This is important to me because it is a one-way road. I cannot reorganize it otherwise, so any feedback matters ...

+4
source share
1 answer

I found the answer in another question.

Question: When should you consider creating only the library header? - and answer is here .

And the answer is that I will tear it into .cpp and .hpp files and make it ready to compile both as a header and in a static library or DLL.

@ Steve Jessop :

If you think that your library without templates can only be for a title, consider splitting it into two files and then providing a third file containing both .h and .cpp (with inclusion protection).

Then anyone who uses your library in many different TUs, and suspects that it may cost a lot of compilation time, can easily make changes to check it.

^ This is an awesome idea. It takes a little more work, but it is so universal.

UPDATE

it’s important to explicitly create templates < .

0
source

Source: https://habr.com/ru/post/1495375/


All Articles