複数条件での enable_if その2

元記事:危ないRiSKのブログ - オーバーロードに優先順位を付ける
なんと、こんなやり方が…!!
ってことで、思わず自分でも書いてみました。
まぁやっている事は元記事の丸パクリなんですがががが。

[ソース]

#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/utility/enable_if.hpp>
#include <iostream>

template<int N>
struct overload_priority
    : overload_priority<N + 1>{};

template<>
struct overload_priority<32>{};

static overload_priority<0> const* const overload = NULL;

template<typename Pred, int Priority>
struct enable_if_priority
    : boost::enable_if<Pred, overload_priority<Priority> const* const>{};

typedef enable_if_priority<boost::is_same<int, int>, 32>::type other;


template<typename T>
void
func(T, typename enable_if_priority<boost::is_same<T, int>, 0>::type){
    std::cout << "int" << std::endl;
}

template<typename T>
void
func(T, typename enable_if_priority<boost::is_integral<T>, 1>::type){
    std::cout << "integral" << std::endl;
}

template<typename T>
void
func(T, other){
    std::cout << "other" << std::endl;
}

template<typename T>
void
func(T t){
    func(t, overload);
}

int
main(){
    func(0);
    func(short(1));
    func(0.0f);
    func("hoge");
    return 0;
}

[出力]

int
integral
other
other

C++03 で書くとこんな感じですかね。
呼び出し元をラップしていますが、それ以外はすっきりしているような?
以前書いたものは条件をまとめた Sequence が必要だったんですが、この書き方だと必要がないので書きやすいですね!
うーむ、これはイイネ!