LoginSignup
4
3

More than 5 years have passed since last update.

TMPでcase

Posted at

Qiitaの投稿練習も兼ねて
タイトルの通りで、C++のTMPでcaseを実現してみようとかいうそういうのです
文章で書くよりコードを見たほうがわかりやすいと思うので例を乗せます

example1.cpp
case_ < char >::of
<
    match < char , long > ,
    match < short , int > ,
    match < int , short > ,
    match < long , char > ,
    match < list < pattern < 0 > , double > , list < double , pattern < 0 > > >
>::type // => long
example2.cpp
case_ < list < float , double > >::of
<
    match < char , long > ,
    match < short , int > ,
    match < int , short > ,
    match < long , char > ,
    match < list < pattern < 0 > , double > , list < double , pattern < 0 > > >
>::type // => list < double , float >

includeやusingなどは省略しています
TMPのために僕自身が作成したライブラリ、FTMPを使用しています
まあ、TMPってこんなこともできるんだよーって話です
これをうまく使えばTMPの際のメタ関数の場合分けがなんとかなるかもしれません

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3