cppflow icon indicating copy to clipboard operation
cppflow copied to clipboard

cppflow2: declare `inline` for header only implementation

Open ljn917 opened this issue 5 years ago • 9 comments

As #73 suggested, non-template function definition in header needs to be declared as inline to avoid ODR violation. This requires changes in both the auto-generated header and the manually written headers.

This may not be important if we are going to separate the implementation into cpp files, but we need to address them if we want to keep the library header only.

ljn917 avatar Nov 22 '20 21:11 ljn917

This has caused me issues as well. For the time being, I just manually added the inline keyword to all the necessary methods in my local copy, but this should probably be implemented.

rustom avatar Nov 24 '20 08:11 rustom

Yes, it's true, we should do something about.

I don't know if we should continue with a header only structure or move the implementations into a cpp files. At the beginning I started the code as a header-only library as I though I would require lot of templated functions, but now is not that the case.

I don't know, perhaps we should switch...

serizba avatar Nov 24 '20 17:11 serizba

I am working on a large project with the constraint of using c ++ 14. Most companies have old Ubuntu 16 in production that are not natively compatible with c ++ 17. Inline variables are implemented from c ++ 17, I chose to switch to the cpp implementation with a static lib compilation to avoid adding cpp to the project files.

khaled-besrour avatar Nov 24 '20 19:11 khaled-besrour

@serizba There are too many people complaining this. Maybe I will add the missing inline declaration to temporarily solve this for now. It seems it is the easiest way to do.

ljn917 avatar Dec 02 '20 20:12 ljn917

Yes, we have to address this.

But I am not sure on whether to stick with the header-only implementation or switch definitions to cpp files.

serizba avatar Dec 03 '20 08:12 serizba

I am not sure either.... In my opinion, it is more like a lib design choice. Both have their own pros and cons. The PR #81 chose to keep header only structure simply because it took the minimum effort to solve this problem. In other words, it is not recommending header-only is better.

ljn917 avatar Dec 03 '20 08:12 ljn917

I think that for the moment I will stick with the header-only implementation and I will accept PR #81.

serizba avatar Dec 03 '20 09:12 serizba

I already made the effort to convert from header to .Cpp/. H implementation. Switching to inline implementation will not break c++ 14 compatibility?

khaled-besrour avatar Dec 03 '20 18:12 khaled-besrour

@khaled-besrour To be honest, I am against moving back to C++ 14 (sorry) because we are considering conditionally importing C++20 features (std::span).

ljn917 avatar Dec 03 '20 19:12 ljn917

As the proverb say:

There is nothing more permanent than a temporary solution.

serizba avatar Sep 23 '22 12:09 serizba