Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Some open source libraries have tendency to re implement basic structures like string, list, stack, queue...
Why don't they use stl library? Is stl not good enough?
C++ as a language existed for many years before the STL was standardized and for several more years before the STL was implemented consistently across all compilers. Libraries that were originally written during that time may not have wanted to rely on the STL in order to be more portable.
Another reason related to portability is embedded use. Qt, for example, re-implements most of the STL because Qt applications are sometimes targeted at embedded platforms (e.g. Nokia smartphones) which may not have an STL implementation available.
Exposing STL types in headers can, in some cases, lead to nasty, nasty link times. On large projects, that can be sufficient reason to "hide" them behind a proprietary-looking API.
STL implementation differ on every platform, so exposing STL in library will have risk, for example if you expose std::map on your library, since you can not export std::map from your library, your library will be forced to use std::map implementation from your library users (the one that load your lib), this will cause some incompatibility such as different version of STL implementation, different STL allocator class, and some platform specific issues.
One of the reasons may be that STL containers are not intended to be used as base classes - STL design issues Wikipedia
To STL or NOT STL that is the question - SO
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
Is there ready unit tests for testing if STL containers are working correctly, something that was used by compiler creators?
I'm making a simple port of the STL in C and need to test the data structures and thought that STL unit tests already existed, but didn't find anything
Is there unit tests for STL containers?
STL does not exist anymore. Read the C++11 standard n3337 and see this C++ reference website. Consider also using Boost.
Both recent GCC and recent Clang provide testsuites for the standard C++ containers library, whose implementation is practically tied to the compiler (because of compiler optimizations)
I'm making a simple port of the STL in C
Then look -at least for inspiration- into Glib (from GTK) and SGLIB. I tend to think that you could use one of them. Given the complexity of the standard C++ library, I believe you won't be able to make from scratch in just a few weeks a simple port of it to C if you care about efficiency. Look also into MILEPOST GCC and read this paper then Artificial Beings: the conscience of a conscious machine ISBN:9781848211018 for some interesting insights.
Otherwise, be sure to read Introduction to algorithms
Notice that with some care, you usually can write in C++ a library callable from C (use extern "C" appropriately and systematically). A good example is of course libgccjit (which you could consider using, for some partial evaluation based approaches: you might generate specialized machine code suited to particular instances of your problems).
If you code your generic container library in C, consider using Frama-C on it, and with a recent GCC, compile it with all warnings and static analysis options. You might even consider writing your GCC plugin to check that users of your library are using it correctly.
See also the European DECODER project.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am extremely new to C++, what is the difference between the C++ Standard Library and the std namespace. I get them confused and don't know when to use which. Also how does the header files correlate with all this?
The C++ standard [template] library is a collection of tools - specifically containers and algorithms - that are useful in a general sense. It is particularly powerful when the algorithms are applied to the containers - when sorting a vector, for example.
Namespaces serve to decorate the symbols defined within them and thus avoid collisions between symbols defined (usually) by different libraries. All standard library code is in namespace std. Thus we have, for example, std::vector, std::sort and a whole lot more.
To pick another library at random, the popular Nlohmann JSON library defines all its symbols in namespace nlohmann, and in the unlikely event that this defined a vector class, it would not clash with the standard library.
You will often see people on SO (and elsewhere) coding using namespace std;, sometimes in a header file, and perhaps you now understand why this practise is not wise.
Does any of that help at all?
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Whats best practice to use: std::thread, native calls, or some library? Is std::thread a 'don't-actually-use-this' convenience, or should it be used whenever threading is needed? Before c++11 came around, it looked like some threading library was best for portability, but now that std::thread is a thing...
What should be used - in terms of industry-standard - in major projects now?
Rule of thumb:
If something has been in the standard library for > X years, use it unless you know it won't fit your needs.
If something has been in the standard library for <= X years, and you're writing non-critical code: Same as before - use it.
Otherwise:
Look for how it got into the standard library (often: Boost);
Snoop around for discussions mentioning both of them, posts by authors, etc.;
Map feature set / design decision differences;
if you still don't have enough information to make a decision, ask here.
In your case, see:
C++ 11 Thread vs Boost Thread is there any difference?
where you'll notice Boost threads have some features not in the standard. If you need those, use the Boost threads, otherwise use std::thread.
There is no one answer to rule them all.
TL;DR It depends
If you want best performance(maybe one of the reasons you are using c++) use native calls. You have full control and no overhead from wrapper classes and checks.
If you need portability and support of c++11 is present the implementation in std is a good choice. Most of the time this option would be the easiest to start with and have most resources available.
Currently the boost duplicates the features of the standard. But it is still viable option if a compiler does not support c++11. In the latest few revisions same boost features are copied directly in the standard.(smart pointers for example)
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
The question has been asked many times here: "How do I iterate through files in a directory in c++?"
I've seen the responses, typically suggesting to use an external library (usually boost filesystem) to handle this and the OS differences in implementation.
My question is: why? Why is this so difficult?
I'm new to the language and can't help but feel that I'm trying to overstep the bounds of idiomatic c++.
Is it more appropriate to implement a single file solution and use another language to implement the file iteration?
Relative to other languages, C++ has a tiny standard library. This has its advantages (porting C++ to a new platform is much easier), but it also means that, to get a lot of things done, you're going to rely on external libraries.
Filesystem work has not, until C++17, been something that has been a part of the C++ standard. And even now, some people are resistant to the C++17 filesystem library because it doesn't work quite so well with certain types of underlying filesystems.
Note that many languages that have standard filesystem support don't support these platforms at all.
I'm new to the language and can't help but feel that I'm trying to overstep the bounds of idiomatic c++.
If you're going to use C++, then you need to accept that you're going to have to go out and use other libraries for a lot of the stuff that many other languages give you for free. Using a library is how you get things done in C++; it's not "overstepping the bounds" of anything.
You can't iterate the files in a directory in C++ without using platform-specific APIs. The core C++ language and the standard library do not provide any mechanism to obtain a directory listing and iterate through it. So in order to do this, you must use an external library or platform specific API.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I need to keep my data in associative table. Something like:
typedef std::map< point, std::list<h_stat> > hm;
But STL containers do not have a ready serialization methods. It is very sad news.
I think, it is not a good idea to link a boost library to my small project.
I program on Windows. Maybe, does windows.h or MFC have a associative table class, that has a serialization method from a box? Or is there another good container for C++ on the Internet?
Thank you in advance.
With MFC you definitively have an easy way for serialisation with CMap and very easy way to make classes serializable.
However it's not so portable. An alternative is boost, which provides for serialisation also for standard containers (see also this answer to a similar question)
s11n is a C++ serialization library which claims that it...
can easily serialize all manner of PODs (Plain Old Data types), most STL containers, and user-defined Serializable types.
You could consider using it (AFAIK, it serializes containers automatically from serialization of constituents).
Otherwise, since your project is small, you should be able (without s11n) to manually add serialization operations to every class. With C++11 it should be relatively easy (thanks to ranged for loops, auto, lambda-expressions).