Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

How do you name your iterators when you return a begin and an end iterator from a class? Without it sounding clunky, that is.

Example:

typedef std::vector<Idea> Ideas_Type;

Ideas_Type::const_iterator GetIdeasBegin() const;
Ideas_Type::const_iterator GetIdeasEnd() const;

Should it be GetIdeasBeginIter? IdeasBegin?

share|improve this question

closed as primarily opinion-based by ChrisF Mar 20 at 9:48

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

    
This question appears to be off-topic because it is a "name that thing" question. "Name that thing" are bad questions for the same reasons that "identify this obscure TV show, film or book by its characters or story" are bad questions: you can't Google them, they aren't practical in any way, they don't help anyone else, and allowing them opens the door for the asking of other types of marginal questions. See blog.stackoverflow.com/2012/02/lets-play-the-guessing-game –  gnat Mar 20 at 8:40

2 Answers 2

up vote 1 down vote accepted

It's unclear from your question, but if you are thinking of something like this:

class Brain {
  typedef std::vector<Idea> Ideas; // Not "Ideas_Type".  That's why it's capitalized.
  Ideas::const_iterator firstIdea();
  Ideas::const_iterator lastIdea();
}

There's no need for all that. You may as well say

class Brain {
  ...
  const Ideas &ideas();
}

By returning a constant reference to the collection, it allows callers to process the collection as they see fit without modifying it. If you don't want to expose the entire vector interface, then you can create a small class like this:

class my_list<T>: private std::vector<T> {
public:
  // whatever methods you like, including begin(), end(), ...
}

And as a matter of style, save "get" methods for legacy languages.

share|improve this answer

I would mimic the naming done in the STL. Now your classes work with many built-in functions.


  • begin
  • end

  • rbegin
  • rend
share|improve this answer
    
There are some libraries that will take advantage of appropriately named interfaces (begin, end for example) to allow operations on a container directly. –  Bill Door Jul 17 '12 at 20:47
4  
Also cbegin and cend in the new standard. –  Klaim Jul 17 '12 at 21:32
    
@BillDoor : cprogramming.com/c++11/c++11-ranged-for-loop.html this requires methods called begin and end be present in your class. –  gbjbaanb Jul 18 '12 at 14:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.