Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to know if some data type is from std?

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.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading