Updates from March, 2012 Toggle Comment Threads | Keyboard Shortcuts

  • Alex Syniakov 23:25 on March 13, 2012 Permalink | Reply

    The 2012-02 post-Kona mailing is available 

    You can check it out here: http://www.open-std.org/jtc1/sc22/wg21/

    The main anticipated, imho, features are:

    static if – it will simplify a huge amount of meta code. 

    range – we 100% need ranges. I think everybody is tired of writing begin/end, even if these pair used only in 5% of code 🙂

    Filesystem Library for C++11 – as you may know, msvc2011 already have <filesystem> header.

    Modules in C++ – it is the major feature of C++. All benefits are listed in proposal. But, for me, the main advantage is get rid off pimple idiom.

    boost.asio – please, make it part of standard library. we want platform-independent network library.


    I know many huge companies that don’t allow using of boost(or any other 3rd party libraries) in their products. I’m tired of this. Please, make it part of standard.

  • Alex Syniakov 00:10 on March 11, 2012 Permalink | Reply

    Tags technique 

    Suppose you’ll need to write some class mat4, that represent transformation 4×4 matrix. This matrix is widely used in graphics. The first question that you need to address as developer is “what default constructor of mat4 should look like?” Well, of course, you can set all elements of matrix to zero. But this kind of matrix is not usable in graphics application. The more common matrix is identity matrix. On the other hand, you want to aware of unnecessary initialization of matrix. Here is the technique that help us to solve all these designing questions.
    Let’s introduce some tags
    in *.h file:

    struct mat4_identity{ static mat4_identity tag; };
    struct mat4_zero{ static mat4_zero tag; };
    struct mat4_unitialized{ static mat4_unitialized tag; };
    _Winnie C++ Colorizer

    in *.cpp file:

    mat4_identity mat4_identity::tag;
    mat4_zero mat4_zero::tag;
    mat4_unitialized mat4_unitialized::tag;
    _Winnie C++ Colorizer

    And delete our default constructor:

    mat4() = delete;
    _Winnie C++ Colorizer

    Now implement three constructors:

    for(size_t i = 0; i &lt; mat4::arity; ++i)
    for(size_t j = 0; j &lt; mat4::arity; ++j)
    data[i][j] = i == j ? scalar(1) : scalar(0);

    for(size_t i = 0; i &lt; mat4::arity; ++i)
    for(size_t j = 0; j &lt; mat4::arity; ++j)
    data[i][j] = scalar(0);

    //yep, it is your decision

    _Winnie C++ Colorizer

    Now we can perform calculations are very quickly. Without additional overhead to matrix initialization.

    mat4 mat4::operator+(const mat4&amp; rhs)
    mat4 result(mat4_unitialized::tag);

    for(size_t i = 0; i &lt; arity; ++i)
    for(size_t j = 0; j &lt; arity; ++j)
    result.data[i][j] = data[i][j] + rhs.data[i][j];

    return result;

    _Winnie C++ Colorizer
  • Alex Syniakov 20:49 on March 10, 2012 Permalink | Reply

    lambda in std::bind, msvc 2010 

    Unfortunately, msvc2010 doesn’t support lambdas as parameter for std::bind. For example,

    you cannot write something like this:

    std::bind([](int x){ return x; },42)();

    The problem is that bind powered by result_of, and vc10 uses old way to handle result of the expression.

    In vc11 it is fixed. Internally result_of uses decltype.

    As always, you can write functor instead of lambda and pass it to bind function:
    class T
    int operator()(int x)
    return x;

    T f;

Compose new post
Next post/Next comment
Previous post/Previous comment
Show/Hide comments
Go to top
Go to login
Show/Hide help
shift + esc