mercredi 20 juin 2018

How to user user defined literal in header?

I have defined the following user-defined literal in MyLiteral.h:

namespace my_literals {
    constexpr uint64_t operator"" _nanoseconds(unsigned long long int value) {
        return value*1000;
    }
}

Now I could use the operator in another header SomeComponent.h:

using namespace my_literals;
namespace foo {
    constexpr uint64_t timeout = 10_nanoseconds;
}

However, I don't want to pollute the scope by using namespace my_literals, because this would provide the literal definition to all *.cpp files which include SomeComponent.h.

How can I avoid this? constexpr uint64_t timeout = my_literals::10_nanoseconds; gives expected unqualified-id before numeric constant in g++.

Aucun commentaire:

Enregistrer un commentaire