Correct way to test if a declaration is within the scope of a namespace (anonymous or not)

Hi all,

I'm trying to test if a declaration is within the scope of a namespace (anonymous or not).
Actually I'm using this code to test this (it's just a hack I know). What is the correct way to do this?

if (ND->getQualifiedNameAsString().find("::") != std::string::npos) {

ND is defined in a namespace
}

  ND is a DeclaratorDeck*

Many thanks in advance.

Best regards.