Skip to content

Architecture overview

Aleksandr edited this page Jul 13, 2019 · 19 revisions

General info

The library provide header files with standard names and '.hpp' equivalent names for each of the std library header that has C++ 11 features (functions, classes etc.). The core features like countof or nullptr implementation and compiler specific stuff is located in core.h.

Usage recommendations

Good call is to global include stdex/core.h in each of your source files and use #include stdex/{standard header name} where you require.

#include <stdex/core.h>

int main()
{
    double *ptr = nullptr;
    return 0;
}

What to expect?

All stdex classes, functions etc. are defined in namespace stdex, so you could not confuse it with namespace std stuff of your default standard library implementation. All C++11 standard macros (like INTMAX_MAX) are defined with prefix STDEX_ (STDEX_INTMAX_MAX f.e.) for the same reason.

  • If the type, class, function or macros is supported by your compiler default C++ standard library, stdex will use it and just carefully define the same symbol in namespace stdex.
  • If the type, class, function or macros is not present or do not provide C++ 11 functionality stdex will define its own implementation in namespace stdex then.

You could write namespace stdex {using namespace std;} and get whole C++ 11 std library in namespace stdex. There should be no conflicts.

#include <iostream>
#include <stdex/string>

namespace stdex {using namespace std;}

int main()
{
    stdex::cout << stdex::to_string(10.f) << stdex::endl;
    return 0;
}

this will work pretty with namespace aliasing too:

#include <iostream>
#include <stdex/string>

namespace stdex {using namespace std;}

int main()
{
    namespace std = stdex; // creating a local alias, C++ standard approves

    //C++98(std)   C++11(stdex)         C++98(std)
    std::cout << std::to_string(10.f) << std::endl;
    std::cout << std::stol("4242424") << std::endl;
    return 0;
}

On practice you may write namespace std {using namespace stdex;} and get whole C++ 11 std library in namespace std. There may be no conflicts as well however it is not welcomed by standard to include your stuff in namespace std. So it is up to you but I recommend to use local namespace alias namespace std = stdex as a safe alternative.

How does it work?

The library heavily rely on SFINAE in compile time and a little bit on compiler-specific functions if and only if there is no other approach. There is no undefined behaviour or compiler-specific hacks, only compile time template magic and some fallbacks for known compiler bugs and not-so-standard implementations of standard features.

Why don't you just use Boost?

Once again - because I can. I personally believe that Boost as whole platform/ framework/ C++ standard experimental field/ research bench/ you-name-it is great. But not as standard library. It is bloated with hacks, compiler-specific macro, macros as general etc. Also it have poor support for QNX qcc and Borland C++ Builder 6.0 compilers.

stdex on the other hand only aims to implement C++ 11 standard as close as possible on top of existing std library, without straight support from compiler, using no undefined behaviour hacks and minimum macros. I try to develop it clean and bloat-free, and I think I'm getting there.