Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::string.npos validity

Was std::string.npos ever valid? (As opposed to the correct std::string::npos.)

I am seeing it a lot in an old project I'm working on, and it does not compile with VS2010.

Is it something from the pre-standard days?

like image 517
Lightness Races in Orbit Avatar asked May 30 '11 21:05

Lightness Races in Orbit


1 Answers

The C with classes syntax for naming a class member was, in fact, a dot:

class X {
public:
    void f();
};

void X.f() // a dot! see D&E 2.3
{ 
}

However, the :: syntax had not yet been invented. The std namespace didn't exist yet either. Thus the std::string.npos wasn't ever valid as either C with classes or standard C++.

I suspect std::string.npos is purely Microsoft's extension (or a bug?). It might be inspired by the old syntax, and might be not.

like image 72
Yakov Galka Avatar answered Sep 29 '22 14:09

Yakov Galka