Home > Back-end >  How to know if some data type is from std?
How to know if some data type is from std?

Time:12-30

Is there any list of types inside std namespace? I'm writing translator from uml diagram to c code, that should add std:: when it's needed. How my program should know that string has prefix std:: and int doesn't.

CodePudding user response:

Is there any list of types inside std namespace?

All of them are mentioned in the standard, as well as any documentation that covers the standard. There's no plain list that I know of however.

How my program should know that string has prefix std:: and int doesn't.

Your program should know that int isn't in a namespace because it is a keyword. You can find a list of all keywords in the [tab:lex.key] table in the standard.

However, just because an identifier is string, doesn't mean that it is in the std namespace. Example:

namespace not_std {
struct string {};
string s; // this isn't std::string
}

#include <string>
using std::string;
string s; // this is std::string

Adding the std:: qualifier would be correct only in the latter case.


I'm writing translator from uml diagram to c code

In my opinion, your translator should translate string into string and std::string into std::string. Let the author of the diagram ensure that their names are correctly qualified. If the translator has to make guesses, then there will be cases where it guesses incorrectly.

  • Related