Answer by jzl106 for Why does std::pair expose member variables?
I was appalled by the number of comments that show no basic understanding of object-oriented design (does that prove c++ is not an OO-language?). Yes the design of std::pair has some historical traits,...
View ArticleAnswer by davidbak for Why does std::pair expose member variables?
Getters and setters are useful if one believes that abstraction is warranted to insulate users from design choices and changes in those choices, now or in the future. The typical example for "now" is...
View ArticleAnswer by user3995702 for Why does std::pair expose member variables?
The primary purpose of getters and setters is to gain control over access. That is to say, if you expose "first" as a variable, any class can read and write (if not const) it without telling the class...
View ArticleAnswer by Ilio Catallo for Why does std::pair expose member variables?
The reason is that no real invariant needs to be imposed on the data structure, as std::pair models a general-purpose container for two elements. In other words, an object of type std::pair<T, U>...
View ArticleAnswer by Dietmar Kühl for Why does std::pair expose member variables?
It could be argued that std::pair would be better off having accessor functions to access its members! Notably for degenerated cases of std::pair there could be an advantage. For example, when at least...
View ArticleAnswer by Hatted Rooster for Why does std::pair expose member variables?
Getters and setters are usually useful if one thinks that getting or setting the value requires extra logic (changing some internal state). This can then be easily added into the method. In this case...
View ArticleAnswer by Cheers and hth. - Alf for Why does std::pair expose member variables?
For the original C++03 std::pair, functions to access the members would serve no useful purpose.As of C++11 and later (we're now at C++17, with C++20 coming up fast) std::pair is a special case of...
View ArticleWhy does std::pair expose member variables?
From http://www.cplusplus.com/reference/utility/pair/, we know that std::pair has two member variables, first and second.Why did the STL designers decide to expose two member variables, first and...
View Article
More Pages to Explore .....