Using a literal suffix name when defining a static constexpr class member

Viewed 70

I'd like to define a static constexpr data member in a class, like

class my_protocol
{
public:
    static constexpr auto comm_timeout = 50ms;
    ...
};

Is there a good way to avoid the using namespace std::literals::chrono_literals; at global scope in the header file that defines this class?

1 Answers

There is still the lambda directly invoked way:

class my_protocol
{
public:
    static constexpr auto comm_timeout = [](){
        using namespace std::literals::chrono_literals;
        return 50ms;
    }();
    // ...
};
Related