MW

Tag c++11

Recent Posts

Maxwell distribution in C++11 (July 29, 2014)

Hey all,

I recently needed to generate values following a Maxwell distribution. Wikipedia gives the hint that this is a Gamma distribution, which in C++11 is easily useable. Thus, thanks to <random>, we can setup a Maxwell distribution in a few lines of code:

    #include <random>
    #include <chrono>
    #include <iostream>
     
    using namespace std;
     
    int main()
    {
        unsigned seed = chrono::system_clock::now().time_since_epoch().count();
        default_random_engine generator(seed);
     
        // Boltzmann factor times temperature
        const double k_T = 0.1;
     
        // setup the Maxwell distribution, i.e. gamma distribution with alpha = 3/2
        gamma_distribution<double> maxwell(3./2., k_T);
     
        // generate Maxwell-distributed values
        for (int i = 0; i < 10000; ++i) {
            cout << maxwell(generator) << endl;
        }
     
        return 0;
    }

Pretty neat, I have to say!

continue reading...

Kate/KDevelop Sprint 2014: Let There Be Clang (February 04, 2014)

Time flies… The extremely productive hack sprint at the friendly Blue Systems office in Barcelona is over for more than a week. I haven’t had time to blog about the last days yet which I hereby make good for!

I spent a lot of time at the sprint polishing the KDevelop Clang plugin. A up-to-now semi-secretly developed language plugin based on clang which will replace our current C++ language support in KDevelop in the long-run.


Code completion ofstd::string in a std::vector.


Showing a clang-generated warning inside the editor.


Nested clang diagnostics with browsing support.

KDevelop’s current C++ plugin

But a bit of history first: KDevelop’s current C++ language plugin can pull off what it does by essentially implementing (parts of) the C++ standard. We have our own C++ parser, we have our own implementation of the C++ template mechanism, we have our own share of “compiler bugs”, …. It should not surprise anyone that this is a maintenance nightmare. And indeed, with C++11 and the wealth of changes it came with our language simply fails in many areas. The current codebase is big (~55k sloc) and adding support for complicated features such as variadic templates or constexpr is extremely hard and fragile. So instead of doing that, my colleague Olivier JG started looking into using clang of LLVM fame instead. It promises an API for third-party tools to steer a C/C++/Objective-C compiler to their needs. Its the magic bullet which we waited for, and which did not exist back when KDevelop 4.0 was started initially.

continue reading...

C++11 platform support? (November 26, 2012)

Hello all!

I’m investigating the feasibility of allowing a subset of C++11 in the KDevelop code base, starting after the branch of 4.5 in a few weeks. I do not want to blindly start going that route just to realize afterwards that I’ve alienated a large portion of our user base. Thus I’d very much welcome if you could read through this blog post and give some feedback which we can build our decision on top.

Here’s the email I sent to the KDevelop development mailing list:

Is anyone opposed to open KDevelop 4.6 for C++11? I.e. that means we continue to work as-is and provide a kick-ass KDevelop 4.5. Once we branch 4.5, we enable C++11 mode globally and start using it in master.

Reasons:
  • KDevelop is a free time project and it should be fun to work on it. C++11 is quite a lot of fun, if not only because it’s new. This is actually the main reason for me to go down the C++11 route. This would also allow us to learn C+11 which is a benefit for those of us who do professional work-work programming.

continue reading...