C++ and C++'0x Support in Clang

が更新されたらしいので、『template aliases』と『In-declaration member initialization』を試してみました。

他にも更新されたのがあるかも。

[ソース]

#include <iostream>
#include <boost/array.hpp>

template<typename T, typename U>
struct is_same{
    static bool const value = false;
};

template<typename T>
struct is_same<T, T>{
    static bool const value = true;
};

// template aliases
template<typename T>
using is_int = is_same<T, int>;

static_assert( is_int<int>::value,  "");
static_assert( is_int<char>::value == false, "");

struct data{
    // In-declaration member initialization
    boost::array<int, 5> array = {{0, 1, 2, 3, 4}};
    float pi = 3.14f;
};

int
main(){
    std::cout << "hello world" << std::endl;
    data d;
    std::cout << d.pi << std::endl;
    for(auto value : d.array){
        std::cout << value << std::endl;
    }
    return 0;
}

[出力]

hello world
3.14
0
1
2
3
4

C++0x が便利過ぎて、C++03 を使うのが辛い。
両方共 gcc 4.7 ではまだ実装がされていないので、いい感じで差別化しているような気がします。
C++0x 早く来い!!


あと本文とは関係ないですけど、いつの間にか、clang + C++0x + Windows でも libc++ が使えるようになっている???
こっちは調べてないのでよく分かっていません。