[complement-svn] SF.net SVN: complement: [1466] trunk/complement/explore/inquiry/STLport
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2006-12-29 13:24:44
|
Revision: 1466 http://svn.sourceforge.net/complement/?rev=1466&view=rev Author: complement Date: 2006-12-29 05:24:41 -0800 (Fri, 29 Dec 2006) Log Message: ----------- function return: increment operator for POD and non-pod; memfunc Added Paths: ----------- trunk/complement/explore/inquiry/STLport/mem_func/ trunk/complement/explore/inquiry/STLport/mem_func/Makefile trunk/complement/explore/inquiry/STLport/mem_func/Makefile.inc trunk/complement/explore/inquiry/STLport/mem_func/mm.cc trunk/complement/explore/inquiry/STLport/tmp_iter/ trunk/complement/explore/inquiry/STLport/tmp_iter/Makefile trunk/complement/explore/inquiry/STLport/tmp_iter/Makefile.inc trunk/complement/explore/inquiry/STLport/tmp_iter/test.cc Property changes on: trunk/complement/explore/inquiry/STLport/mem_func ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/explore/inquiry/STLport/mem_func/Makefile =================================================================== --- trunk/complement/explore/inquiry/STLport/mem_func/Makefile (rev 0) +++ trunk/complement/explore/inquiry/STLport/mem_func/Makefile 2006-12-29 13:24:41 UTC (rev 1466) @@ -0,0 +1,10 @@ +# -*- Makefile -*- Time-stamp: <03/07/09 18:08:47 ptr> + +SRCROOT := ../../.. +COMPILER_NAME := gcc + +include Makefile.inc +include ${SRCROOT}/Makefiles/top.mak + +LDFLAGS += -Wl,-rpath=$(STLPORT_LIB_DIR) + Added: trunk/complement/explore/inquiry/STLport/mem_func/Makefile.inc =================================================================== --- trunk/complement/explore/inquiry/STLport/mem_func/Makefile.inc (rev 0) +++ trunk/complement/explore/inquiry/STLport/mem_func/Makefile.inc 2006-12-29 13:24:41 UTC (rev 1466) @@ -0,0 +1,4 @@ +# -*- makefile -*- Time-stamp: <02/07/14 14:03:13 ptr> + +PRGNAME = test +SRC_CC = mm.cc Added: trunk/complement/explore/inquiry/STLport/mem_func/mm.cc =================================================================== --- trunk/complement/explore/inquiry/STLport/mem_func/mm.cc (rev 0) +++ trunk/complement/explore/inquiry/STLport/mem_func/mm.cc 2006-12-29 13:24:41 UTC (rev 1466) @@ -0,0 +1,39 @@ +#include <iostream> +#include <string> +#include <vector> +#include <functional> +#include <algorithm> + +class Person +{ + private: + std::string name; + + public: + //... + void print () const + { std::cout << name << std::endl; } + + void printWithPrefix (std::string prefix) const + { std::cout << prefix << name << std::endl; } +}; + +void foo (const std::vector<Person>& coll) +{ + using std::for_each; + using std::bind2nd; + using std::mem_fun_ref; + + // call member function print() for each element + for_each( coll.begin(), coll.end(), mem_fun_ref(&Person::print) ); + + // call member function printWithPrefix() for each element + // - "person: " is passed as an argument to the member function + for_each( coll.begin(), coll.end(), bind2nd(mem_fun_ref(&Person::printWithPrefix), "person: ") ); + for_each( coll.begin(), coll.end(), bind2nd(mem_fun_ref(&Person::printWithPrefix), std::string("person: ") ) ); +} + +int main() +{ + return 0; +} Property changes on: trunk/complement/explore/inquiry/STLport/tmp_iter ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/explore/inquiry/STLport/tmp_iter/Makefile =================================================================== --- trunk/complement/explore/inquiry/STLport/tmp_iter/Makefile (rev 0) +++ trunk/complement/explore/inquiry/STLport/tmp_iter/Makefile 2006-12-29 13:24:41 UTC (rev 1466) @@ -0,0 +1,10 @@ +# -*- Makefile -*- Time-stamp: <03/07/09 18:08:47 ptr> + +SRCROOT := ../../.. +COMPILER_NAME := gcc + +include Makefile.inc +include ${SRCROOT}/Makefiles/top.mak + +LDFLAGS += -Wl,-rpath=$(STLPORT_LIB_DIR) + Added: trunk/complement/explore/inquiry/STLport/tmp_iter/Makefile.inc =================================================================== --- trunk/complement/explore/inquiry/STLport/tmp_iter/Makefile.inc (rev 0) +++ trunk/complement/explore/inquiry/STLport/tmp_iter/Makefile.inc 2006-12-29 13:24:41 UTC (rev 1466) @@ -0,0 +1,4 @@ +# -*- makefile -*- Time-stamp: <02/07/14 14:03:13 ptr> + +PRGNAME = test +SRC_CC = test.cc Added: trunk/complement/explore/inquiry/STLport/tmp_iter/test.cc =================================================================== --- trunk/complement/explore/inquiry/STLport/tmp_iter/test.cc (rev 0) +++ trunk/complement/explore/inquiry/STLport/tmp_iter/test.cc 2006-12-29 13:24:41 UTC (rev 1466) @@ -0,0 +1,67 @@ +/* +end() return rvalue (Standard, 3.10 par. 5) + +If this is a POD, increment/decrement operators invalid in this context; +If this is user-defined object, temporary object created from rvalue +(Standard, 12.2; 6.6.3) and increment/decrement operators may be valid; + +Usage POD type for string iterator is effective and don't contradict to +Standard. + +So the code + +char c = *(--s.end()); + +is implementation-specific and that's why not good. + +[this is explanation why this code work if begin() return v, but not work +when end() return char *; inspired by string::iterator] +*/ +#include <string> + +using namespace std; + +class v +{ + public: + v& operator ++() { return *this; } +}; + +class vconst +{ + public: + vconst& operator ++() { return *this; } +}; + + +class q +{ + public: + v begin() + { return v(); } + + vconst begin() const + { return vconst(); } + + char *end() + { return 0; } + + private: +}; + +int main() +{ + q x; + + ++x.begin(); + ++x.end(); + + // string s( "123456" ); + + // --s.end(); + + // char c = *(--s.end()); + + return 0; +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |