News for hackers. Stuff that matters.
Re:Mio – Cross-platform header-only C++11 library for memory... by yread on Saturday October 20, 2018 @01:24PM (#18264301)
not a C++ person here but is header-only library an advantage?
Re:Mio – Cross-platform header-only C++11 library for memory... by orbifold on Saturday October 20, 2018 @01:39PM (#18264395)
Yes because there is no standardised build system for C++, which makes integrating non-header only libraries a pain (or at least somewhat more painful), especially if your aim is cross platform code. In that case you can not rely on a reasonable package manager being present and will have to essentially include all your dependencies in the build, this is trivial for header only libraries.
Re:Mio – Cross-platform header-only C++11 library for memory... by asveikau on Sunday October 21, 2018 @11:14AM (#18268402)
Overstated problem. It's not that hard under most circumstances to build a static lib.

I think there are two issues. In C++, a header only library makes sense due to templates, which don't produce object code before specialization. In C, I have seen the same with entirely macro-based "libraries" that are really simulating templates in order to make abstract data structures.

The second case though, my theory is that there is a new generation of programmers who don't understand the traditional compile and link phases because they are used to other languages. It doesn't fit their expectation of how it should work so they bend the tool to their expectation instead of figuring out the old way. The very fact that people on here are saying a programming language should have a "standard package manager" demonstrates the cultural divide: this sounds a little nutty to an old time C person.

Re:Mio – Cross-platform header-only C++11 library for memory... by anonknowsaguy on Monday October 22, 2018 @08:57AM (#18274220)
As newer generation C++ programmer, can confirm I'm guilty of writing things header only when they "probably shouldn't be". But it's not so much I don't understand the old way. Having everything in one file is just so much easier to work with. The price you pay for it is relatively low(for small projects like this library).
Re:Mio – Cross-platform header-only C++11 library for memory... by StreamBright on Saturday October 20, 2018 @02:32PM (#18264699)
Is there a reason not to have a standard build system?
Re:Mio – Cross-platform header-only C++11 library for memory... by twic on Saturday October 20, 2018 @03:19PM (#18264924)
There's no reason not to have one, but there isn't one. There are a few build systems for C++, but none of them are perfect, and none has won out.
Re:Mio – Cross-platform header-only C++11 library for memory... by tom_ on Saturday October 20, 2018 @02:58PM (#18264843)
No consensus on how it should work, and the standard anyway deals with the runtime environment rather than the tooling.
Re:Mio – Cross-platform header-only C++11 library for memory... by rkangel on Saturday October 20, 2018 @01:48PM (#18264456)
The advantage is how easy they are to integrate - just put the file in your tree and then #include. No build option or compiler issues.

The disadvantage (and the reason that I'm personally not a fan) is that they bloat compile time. If it's a library you compile it once, and then it gets linked repeatedly, but a header only library is compiled every time any CPP file that includes it is compiled.

Re:Mio – Cross-platform header-only C++11 library for memory... by makecheck on Saturday October 20, 2018 @02:23PM (#18264650)
“Compiled every time” is not really true if the header correctly contains “#pragma once” or #ifdef guards.

It may be that you have used a lot of template-based headers, which may compile nearly every time because they are literally creating new code every time a new combination of template parameters is given.

Re:Mio – Cross-platform header-only C++11 library for memory... by rkangel on Saturday October 20, 2018 @02:50PM (#18264805)
It'll be compiled once for every Cpp file that includes it. Pragma once (or ifdefs) means that it only gets included once for that compilation, and has no effect on any other Cpp files.

You are correct that I'm mostly talking about template heavy header files. There is a strong correlation between template based header files and header only libraries. The matter) latter generally means the former.

Re:Mio – Cross-platform header-only C++11 library for memory... by jcelerier on Saturday October 20, 2018 @04:39PM (#18265322)
> It'll be compiled once for every Cpp file that includes it.

but are you going to mmap stuff in all your .cpps ? Most of the time when I use an external library, it does not get out of a single implementation file, so it being header only does not really make it worse

Re:Mio – Cross-platform header-only C++11 library for memory... by paavoova on Saturday October 20, 2018 @05:02PM (#18265453)
You still have to compile the library each time you recompile whichever source file includes it. If the library had its own source file, you would only have to compile once and link it thereafter. This adds up if you have a lot of header-only libraries in your code base, and the total LoC may very well dwarf your own codebase. This is where precompiled headers come in, but introduce their own downsides.
Re:Mio – Cross-platform header-only C++11 library for memory... by Fronzie on Sunday October 21, 2018 @04:43AM (#18267198)
Setting up the dependency infrastructure is a bit of work in C++. Recently things have been moving forward, with tools like Cmake+Conan or vcpkg becoming more popular.

Once the infrastructure is sorted out, header-only has mainly disadvantages, like making it harder to separate interface from implementation.

There's a good talk on the topic: https://youtu.be/sBP17HQAQjk

Re:Mio – Cross-platform header-only C++11 library for memory... by steveklabnik on Saturday October 20, 2018 @01:24PM (#18264306)
It's generally considered one, yes.
Re:Mio – Cross-platform header-only C++11 library for memory... by ketzu on Saturday October 20, 2018 @01:38PM (#18264391)
In C++ header-only libraries are nice as they do not need a separate compile and linking step.
Re:Mio – Cross-platform header-only C++11 library for memory... by dima55 on Saturday October 20, 2018 @01:54PM (#18264485)
If you're the sort of person that C++ is a good language then yes. Otherwise, no. It has exactly the issues you think it has.