Clang に Inheriting constructors と Thread-local storage が実装された


と、いうことらしいので早速コンパイルして試してみました。

[ソース]

struct foo{
    constexpr foo(int x, int y, int z)
        : x(x)
        , y(y)
        , z(z)
    {}
    int x, y, z;
};

struct hoge : foo{
    using foo::foo;
};


#include <type_traits>


template<typename base>
struct inheriting_constructor : base {
    using base::base;
};


struct base1{
    constexpr base1(int value) : value(value){}

    int value;
};


struct base2{
    constexpr base2(int value1, int value2) : value(value1 + value2){}

    int value;
};


// template<bool B>
// struct X : std::conditional<B, base1, base2>::type{
// //    using base1::base1 ???
// //    using base2::base2 ???
// };
// 
// constexpr X<true> x{ 42 };
// constexpr X<false> x2{ 23, -9 };


template<bool B>
struct X :
    inheriting_constructor<
        typename std::conditional<B, base1, base2>::type
    >
{
    using inheriting_constructor<
        typename std::conditional<B, base1, base2>::type
    >::inheriting_constructor;
};


#include <iostream>

int
main(){
    constexpr hoge h = hoge(1, 2, 3);
    static_assert(h.x == 1, "");
    static_assert(h.y == 2, "");
    static_assert(h.z == 3, "");

    constexpr X<true> x{ 42 };
    constexpr X<false> x2{ 23, -9 };
    static_assert(x.value == 42, "");
    static_assert(x2.value == 23 + -9, "");

    return 0;
}


とりあえず、Inheriting constructors だけ試してみましたがちゃんと動作しているみたいですね。
これでひと通りの C++11 の言語機能が実装されました。
今月末に LLVM の Developer Meetings も控えていますし、Clang 3.3 に間に合いそうですね。
次期標準の C++1y の実装も予定されているみたいですし今後も楽しみですね。
ちなみに Clang 3.3 は6月辺りにリリースされるとかされないとか。

[コンパイラ]

  • clang++ (LLVM) 3.3 20130420(trunk)