Is There Anything Like a Templatized Case-Statement

后端 未结 5 973
没有蜡笔的小新
没有蜡笔的小新 2020-12-16 18:18

So I have this really ugly code:

template 
std::conditional_t

        
5条回答
  •  误落风尘
    2020-12-16 18:18

    As long as you understand the risk that the same sized type may not be the convertible, you could simply plugin a mpl::map..

    typedef map<
          pair, char>,
          pair, short>,
          pair, int>,
          pair, long long>
        > m;
    

    e.g.

    #include 
    #include 
    
    #include 
    #include 
    
    using namespace boost::mpl;
    
    typedef map<
          pair, char>,
          pair, short>,
          pair, int>,
          pair, long long>
        > m;
    
    template 
    typename at>::type foo(T bar)
    { return reinterpret_cast(bar); }
    
    
    struct doh
    {
        std::string a, b, c;
    };
    
    int main()
    {
        {
          char c;
          static_assert(std::is_same::value, "error");
        }
        {
          short c;
          static_assert(std::is_same::value, "error");
        }
        {
          int c;
          static_assert(std::is_same::value, "error");
        }
        {
          long long c;
          static_assert(std::is_same::value, "error");
        }
        {
          double c;
          static_assert(std::is_same::value, "error");
        }    
        {
          doh c;
          static_assert(std::is_same::value, "error");
        }    
    }
    

提交回复
热议问题