- function returning iterator in C
- vector<string> types;
- // some code here
- Iterator Union::types()
- {
- return types.iterator();
- }
- std::vector<string>::iterator Union::types()
- {
- return types.begin();
- }
- std::pair<std::vector<std::string>::iterator,
- std::vector<std::string>::iterator> Union::types()
- {
- return std::make_pair(types.begin(), types.end());
- }
- std::pair<std::vector<std::string>::iterator,
- std::vector<std::string>::iterator> p = Union::types();
- for (; p.first != p.second; p.first++)
- {
- }
- std::vector<string>::iterator Union::begin()
- {
- return types.begin();
- }
- std::vector<string>::iterator Union::end()
- {
- return types.end();
- }
- std::vector<string>::const_iterator Union::begin()const
- {
- return types.begin();
- }
- std::vector<string>::const_iterator Union::end()const
- {
- return types.end();
- }
- std::vector<string>::const_iterator Union::types_begin() const {
- return types.begin();
- }
- std::vector<string>::const_iterator Union::types_end() const {
- return types.end();
- }
- std::vector<std::string> types;
- // some code here
- std::vector<std::string>::iterator Union::returnTheBeginIterator()
- {
- return types.begin();
- }
- std::vector<std::string>::iterator Union::typesBegin()
- {
- return types.begin();
- }
- std::vector<std::string>::iterator Union::typesEnd()
- {
- return types.end();
- }
- // alias, because the full declaration is too long
- typedef std::vector<std::string> VecStr ;
- void foo(Union & p_union)
- {
- VecStr::iterator it = p_union.typesBegin() ;
- VecStr::iterator itEnd = p_union.typesEnd() ;
- for(; it != itEnd; ++it)
- {
- // here, "*it" is the current string item
- std::cout << "The current value is " << *it << ".n" ;
- }
- }
- void foo(std::vector<std::string> & p_types)
- {
- for(std::string & item : p_types)
- {
- // here, "item " is the current string item
- std::cout << "The current value is " << item << ".n" ;
- }
- }
- std::vector<std::string> types
- std::vector<std::string>::iterator Union::types(){
- return types.begin();
- }
- class Union
- {
- std::vector< std::string > types
- public:
- typedef std::vector< std::string >::iterator iterator;
- iterator begin() { return types.begin(); }
- iterator end() { return types.end(); }
- };