1

I got an interesting question yesterday. I have some C++ code on Linux, which I might give to an Android-team. They asked whether I could omit usage of STL. This leads to a generic question of how you detect usage of STL in C++ code?

My best solutions, which is most likely not the nicest is to search for the following header files, remove them and compile.

#include <vector>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <iterator>
#include <iterator>
#include <algorithm>
#include <numeric>
#include <numeric>
#include <functional>
#include <utility>
#include <memory>

Better solutions?

Peter Toft
  • 565
  • 7
  • 19
  • 1
    You could try searching for `std` in your project. Either you'll find `using namespace std`, in which case removing those statements will cause any declarations of stl types to error out, or you'll find explicit `std::class` variable declarations. – cf- Feb 24 '14 at 06:22
  • 1
    It's not clear on what you mean by `STL`. This is an incomplete list of headers. Do you only want to use c-style headers, like `cstdio` and not `iostream`, even though it's not on the list? Why do you need to remove these headers afterwards? Why not forbid programmers from using it and checking that code in? How does only removing the headers help when the code will fail to compile without the headers in there? –  Feb 24 '14 at 06:27
  • Did they explain what they meant by the STL? Is it the sub-set of the C++ standard library that came from the STL? Is it the actual STL? Or is it the C++ standard library? – juanchopanza Feb 24 '14 at 06:52
  • 1
    I don't see the problem with the above approach. You can't use an STL if you're not including the STL headers. You might want to include `` and `` as well. – Csq Feb 24 '14 at 07:11

1 Answers1

2

Compile your code with gcc (not g++), it is not linked with C++ standard library by default.

Spock77
  • 3,256
  • 2
  • 30
  • 39