4

Is there a correct way to handle APIs that invent their own types?

For example, WinAPI, QT, Boost.

Many frameworks have their own integer and boolean types, along with more complicated data-types.

So, is it better to use native C/C++ type like bool or alternatives like QBool/BOOL/etc., and native container types like std::map/std::set/std::vector vs reinvented ones like QList/boost::something/ATL::map/etc.

And how do those choices respond to cross platform portability.

TL;DR

Which one QBool IsInteresting(const QString &str) vs bool IsInteresting(const std::string &str)?

2 Answers 2

4

Frameworks that have their own replacements for standard library types usually do so because they are also compatible with platforms that do not have a good standard library implementation (such as phones and other embedded systems).

Boost is a special case - it is often practically considered part of the standard library, and several of the highly-used boost libraries were considered for C++0x (some made it, e.g. shared_ptr). Where possible and useful boost is compatible with the C++ standard (library) types.

If you are going to use the same framework for all your product releases and it covers the majority of your needed functionality, it is probably a good idea to save yourself the headache and use the framework's types. That way you don't have to convert back and forth all the time.

If you are going to use multiple GUI frameworks (e.g.if you are targeting multiple platforms not all supported) or if you are using multiple third-party libraries with incompatible types things get more complicated, and you'll have to put some thought into whichever solution has the lowest total impact for your particular project.

4

Always use Standard containers and types where possible. Reinvented containers and types only exist because the libraries in question pre-date Standardisation.

4
  • 1
    Qt doesn't predate standardization. Yet, they have QBool. Commented Aug 11, 2011 at 9:27
  • 2
    Initial Qt development was somewhere around 1998, i.e. at the same time the first c++ standard was released. But since the uptake of standard features in the compilers was slow, and QOI - especially in regard to the stl - was low, qt needed their own types. Commented Aug 11, 2011 at 10:17
  • 1
    @Coder: Qt dates back to 1991, several years before the current C++ standard. Commented Aug 11, 2011 at 10:21
  • Even Wikipedia says that their first release was 1992. Commented Aug 11, 2011 at 11:08

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.