Is it possible to check if a user literal is defined for given type and argument?

前端 未结 2 1853
刺人心
刺人心 2021-01-04 09:33

I want to check at compile-time if user literal _name is defined for type Ret and argument Arg. While I have half-solution, it require

2条回答
  •  死守一世寂寞
    2021-01-04 09:51

    With is_detected functions family, you may just do

    template 
    using has_literal_x_type = decltype(operator"" _x(std::declval()));
    
    template 
    using has_literal_x = std::is_same>;
    

    And test it with

    static_assert(!has_literal_x::value, "unexpected");
    static_assert(!has_literal_x::value, "unexpected");
    static_assert(!has_literal_x::value, "unexpected");
    static_assert(!has_literal_x::value, "unexpected");
    static_assert(!has_literal_x::value, "unexpected");
    

    Demo

提交回复
热议问题